this api project is not authorized to use this API

27,825

Solution 1

I found the answer,

The problem was in my code at this line:

public void requestDirection() {

        snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
        snackbar.show();
        GoogleDirection.withServerKey(getString(R.string.google_api_key))
                .from(origin)
                .to(destination)
                .transportMode(TransportMode.DRIVING)
                .execute(this);

        confirm.setEnabled(false);
    }

R.string.google_api_key's value was feeded by another key from strings.xml. For now, I gave a direct value to withServerKey until I found the the problem with my strings.xml.

public void requestDirection() {

        snackbar = Snackbar.make(view, getString(R.string.fare_calculating), Snackbar.LENGTH_INDEFINITE);
        snackbar.show();
        GoogleDirection.withServerKey("[api key]")//getString(R.string.google_api_key))
                .from(origin)
                .to(destination)
                .transportMode(TransportMode.DRIVING)
                .execute(this);

        confirm.setEnabled(false);
    }

Solution 2

You need to enable the required APIs in the google Developer console : https://console.developers.google.com/

Select your project on the Top Left corner and then click on the "ENABLE API AND SERVICES" button in the dashboard.

Note that you may need to enable more than 1 API (Directions, Geolocating,Geocoding etc) based on your requirement.

Solution 3

To resolve this issue if you hit polyline Api:

https://console.developers.google.com/google/maps-apis/apis/directions-backend.googleapis.com/metrics?project=light-router-266008

Need to enable the APIs:

  1. GeoLocation API
  2. Directions API

Solution 4

If you think you have enabled all, Then you may missed changing your manifest.xml file like :

        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" /> 

Add these tags under application tag

Share:
27,825
Rasool Ahmed
Author by

Rasool Ahmed

Updated on January 05, 2021

Comments

  • Rasool Ahmed
    Rasool Ahmed over 3 years

    I made a taxi booking project that uses google maps api to locate cabs, pickup and drop locations.

    The problem is when I request a ride the following error occurs:

    This API project is not authorized to use this API
    

    Note that I had enabled all google map api services then regenerate the key and the problem is still exist.

    How to solve this?