简体   繁体   English

使用 Google Places 提供的 API 密钥无效

[英]The provided API key is invalid using Google Places

I am trying to implement the Google Places API in an android app but I get the following exception.我正在尝试在 android 应用程序中实现 Google Places API,但出现以下异常。

 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.我创建了 SHA1 代码并限制了 android 应用程序并添加了 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我遵循了这个例子: How to implement google places autocomplete programmatically

Any ideas on how to fix this issue?有关如何解决此问题的任何想法?

play-services-places:17.0.0 places dependency is deprecated play-services-places:17.0.0 places依赖已弃用

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请这个这个有一个完整的自动完成示例在此处输入图像描述

Click Create credential -> API Key .单击创建凭据-> API 密钥 You will get an API key.您将获得一个 API 密钥。 Now enable google places API and put your API key in your project.现在启用 google places API 并将您的 API 密钥放入您的项目中。 You will get the result你会得到结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM