简体   繁体   English

Google Places API自动完成-REQUEST_DENIED

[英]Google Places API autocomplete - REQUEST_DENIED

I'm having a difficult time getting a valid autocomplete response from the Google Places API. 我很难从Google Places API收到有效的自动填充响应。 I'm using code based on [their example}( https://developers.google.com/places/training/autocomplete-android ) (which, interestingly is using a seemingly invalid country code of "uk" ). 我正在使用基于[他们的示例}( https://developers.google.com/places/training/autocomplete-android )的代码(有趣的是,它使用了看似无效的国家代码“ uk” )。

I have enabled Places API in my Google Code Console. 我在Google代码控制台中启用了Places API。 My API key was generated when I first enabled the Maps API a couple of weeks ago, and the MapFragment I'm using is working perfectly, so I have no reason to suspect that the API key is invalid. 我的API密钥是在几周前首次启用Maps API时生成的,而我正在使用的MapFragment运行正常,因此我没有理由怀疑API密钥无效。

The URL I'm using is https://maps.googleapis.com/maps/api/place/autocomplete/json?input=New+York&sensor=false&key=my_valid_api_key&components=country:us 我使用的网址是https://maps.googleapis.com/maps/api/place/autocomplete/json?input=New+York&sensor=false&key=my_valid_api_key&components=country:us

I always get {"status":"REQUEST_DENIED","predictions":[]} as my response. 我总是收到{"status":"REQUEST_DENIED","predictions":[]}作为回应。

I have verified multiple times that my url is formed correctly and adheres to the requirements of the Places API autocomplete endpoint , yet I do not get the response I'm expecting. 我已经多次验证我的网址格式正确,并且符合Places API自动完成端点的要求,但是我没有收到期望的响应。

I have seen a number of suggestions of how to fix this on SO and elsewhere, but none of them have worked for me (ie-using http instead of https, use port 443, etc.) I have tried these in all reasonable combinations with no change in the response. 我已经看到了一些关于如何在SO和其他地方解决此问题的建议,但是没有一个对我有用(例如,使用http代替https,使用端口443,等等。)响应没有变化。

Please help me find what I'm doing wrong. 请帮助我找出我在做错什么。

I tried the URL you provided with my key and it returned the expected results. 我尝试了用密钥提供的URL,它返回了预期的结果。 I suspect you are using an Android key instead of a Browser key. 我怀疑您使用的是Android密钥而不是浏览器密钥。 Try creating and using a Browser key (under "Simple API Access"). 尝试创建和使用浏览器键(在“简单API访问”下)。

Use the server or browser key instead of the iOS key. 使用服务器或浏览器密钥而不是iOS密钥。 Keep the refers field blank to allow all refers. 将引荐字段保留为空白以允许所有引荐。 Here is a sample project which does the same : https://github.com/manishnath/Autocomplete 这是一个执行相同操作的示例项目: https : //github.com/manishnath/Autocomplete

REQUEST_DENIED表示您的请求被拒绝,通常是因为缺少传感器参数。

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&sensor=true&key=AddYourOwnKeyHere

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

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