0

I am trying to implement the Google Places API in an android app but I get the following exception.

 W/System.err: java.util.concurrent.ExecutionException: com.google.android.gms.common.api.ApiException: 9011: The provided API key is invalid.
    W/System.err:     at com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61)
    W/System.err:     at com.google.android.gms.tasks.Tasks.await(Unknown Source:33)
            at com.example.smartorders.PlaceAutoCompleteAdapter.getPredictions(PlaceAutoCompleteAdapter.java:128)
            at com.example.smartorders.PlaceAutoCompleteAdapter.access$100(PlaceAutoCompleteAdapter.java:42)
            at com.example.smartorders.PlaceAutoCompleteAdapter$1.performFiltering(PlaceAutoCompleteAdapter.java:80)
            at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
            at android.os.Handler.dispatchMessage(Handler.java:105)
            at android.os.Looper.loop(Looper.java:164)
            at android.os.HandlerThread.run(HandlerThread.java:65)
        Caused by: com.google.android.gms.common.api.ApiException: 9011: The provided API key is invalid.
    W/System.err:     at com.google.android.libraries.places.internal.zzbo.zza(com.google.android.libraries.places:places@@2.2.0:5)
            at com.google.android.libraries.places.internal.zzby.then(com.google.android.libraries.places:places@@2.2.0:2)
            at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
            at android.os.Handler.handleCallback(Handler.java:789)
            at android.os.Handler.dispatchMessage(Handler.java:98)
            at android.os.Looper.loop(Looper.java:164)
            at android.app.ActivityThread.main(ActivityThread.java:6541)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

I have double-checked that billing is enabled in my account. I have created the SHA1 code and restricted the android app and added the API Places. I have created a second key and did all the above but still no luck. I have followed this example: How to implement google places autocomplete programmatically

Any ideas on how to fix this issue?

Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
cousma
  • 87
  • 1
  • 10

1 Answers1

1

play-services-places:17.0.0 places dependency is deprecated

implementation 'com.google.android.gms:play-services-places:17.0.0'

changes to

`implementation 'com.google.android.libraries.places:places:2.2.0'`

please this one this there is a full example of AutoComplete enter image description here

Click Create credential -> API Key. You will get an API key. Now enable google places API and put your API key in your project. You will get the result

Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
  • I do have this dependency com.google.android.libraries.places:places:2.2.0 – cousma Apr 17 '20 at 13:34
  • I have followed what the link with the Place AutoComplete does. My app shows this error :Status{statusCode=The provided API key is invalid., resolution=null} It goes in here @Override public void onError(Status status) { // TODO: Handle the error. Log.i(TAG, "An error occurred: " + status); } and throws this error what could be wrong with the api key?? When i search for a place the Autocomplete widget which is in OVERLAY mode goes away and no places are displayed.. – cousma Apr 17 '20 at 14:09
  • remove the previous key and add new key – Nensi Kasundra Apr 17 '20 at 14:15
  • i created a new key and now it works!! I think the error was caused by an > at the end of the key in my strings.xml. what a silly mistake! I have spent more than a day to make this work... – cousma Apr 17 '20 at 14:32
  • ok now finally it solved can you please upvote and accept my answer!!! – Nensi Kasundra Apr 18 '20 at 06:32
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/211925/discussion-between-nensi-kasundra-and-cousma). – Nensi Kasundra Apr 18 '20 at 10:54