简体   繁体   English

Google Places 自动完成 api - REQUEST_DENIED

[英]Google places autocomplete api - REQUEST_DENIED

I'm creating app that use autocomplete places google api.我正在创建使用自动完成位置 google api 的应用程序。

And I don't know what is wrong but all the time I got responses like:而且我不知道出了什么问题,但我一直收到以下回复:

{
    "predictions" : [],
    "status" : "REQUEST_DENIED"
}

It was solved for me when I exchanged the API key.当我交换 API 密钥时,它为我解决了。 I was using the one under Android device, I changed it to the one "Key for browser apps (with referers)" and it worked for me although I'm using Android Device.我使用的是 Android 设备下的那个,我将其更改为“浏览器应用程序的密钥(带引用者)”,尽管我使用的是 Android 设备,但它对我有用。

You should be able to view your API Key by going to the API Console first: https://code.google.com/apis/console您应该能够通过首先转到 API 控制台来查看您的 API 密钥: https ://code.google.com/apis/console

If you haven't yet, you will need to create a new "Project" and then enable the Predictions services first by using the On/Off switch.如果您还没有,您将需要创建一个新的“项目”,然后首先使用 On/Off 开关启用预测服务。

Please post your results, I have a similar problem with getting the REQUEST_DENIED response, but I've already got the API key and I'm using the sensor parameter like their documentation states.请发布您的结果,我在获得 REQUEST_DENIED 响应时遇到了类似的问题,但我已经获得了 API 密钥,并且我正在使用传感器参数,就像他们的文档状态一样。

It is frustrating that Google doesn't give any sort of response code along with REQUEST_DENIED so you can see why it's denying it.令人沮丧的是,Google 没有提供任何类型的响应代码以及 REQUEST_DENIED,因此您可以了解它为什么拒绝它。 This will be difficult to support and troubleshoot in a production environment if this randomly goes out without providing any details as to why.如果在没有提供任何详细信息的情况下随机出现,这将很难在生产环境中支持和排除故障。

Update:更新:

I just found this works for me now, but only after changing my requests to GET requests instead of POST.我现在才发现这对我有用,但只有在将我的请求更改为 GET 请求而不是 POST 之后。 For reasons unknown, Google returns REQUEST_DENIED for POST requests but allows the same request via GET.由于未知原因,Google 会为 POST 请求返回 REQUEST_DENIED,但允许通过 GET 进行相同的请求。 A quick test for you to see if this is your problem would be to put the URL together with your API key and other parameters and try it through your browser instead.一个快速测试,看看这是否是您的问题,将 URL 与您的 API 密钥和其他参数放在一起,然后通过您的浏览器进行尝试。 If that works then just rewrite your Android code to use GET instead of POST and you should be all set.如果可行,那么只需重写您的 Android 代码以使用 GET 而不是 POST,您应该已经准备就绪。

Make sure you API keys are generated correctly and that you have enabled the necessary APIS.确保您的 API 密钥生成正确并且您已启用必要的 APIS。 In my case, when designing iOS application - I need to enable Google Maps SDK for iOS, Google Places API for iOS就我而言,在设计 iOS 应用程序时 - 我需要启用适用于 iOS 的 Google Maps SDK、适用于 iOS 的 Google Places API

And most importantly, and without being mentioned by Google (in any other place as well) enable Google Places API Web Service .最重要的是,在没有被 Google 提及的情况下(在任何其他地方也是如此)启用 Google Places API Web Service

With this, I ended a 2 day search for my pesky problem.有了这个,我结束了对我讨厌的问题的 2 天搜索。

And, of course, make sure you use Key for server applications当然,请确保您将Key 用于服务器应用程序

I recommend using .getJson() to get an error message along with your response to know what is exactly wrong.我建议使用 .getJson() 来获取错误消息以及您的响应,以了解究竟是什么错误。

For my case in flutter: I used googlePlace!.autocomplete.getJson(value);对于我的情况:我使用了googlePlace!.autocomplete.getJson(value); and i got the following response.我得到了以下回复。

{ "error_message" : "You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable Learn more at https://developers.google.com/maps/gmp-get-started", "predictions" : [], "status" : "REQUEST_DENIED" }

That's the wrong API key.那是错误的 API 密钥。 Follow the steps here to get the right one.按照此处的步骤获得正确的。

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

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