不建议使用无密钥访问Google Maps Platform [英] Keyless access to Google Maps Platform is deprecated

查看:211
本文介绍了不建议使用无密钥访问Google Maps Platform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时候,当我尝试使用Google MAPS API KEY来获取绘制折线"的网址时,我的日志中出现了错误:

Sometimes when I try to use the Google MAPS API KEY to get a URL to draw a 'polyline', i get an error in my logs:

"error_message":不建议使用无密钥访问Google Maps Platform.请在所有API调用中使用API​​密钥,以避免服务中断.有关更多详细信息,请参阅http://g.co/dev/maps-没有帐户",路线":[],状态":"OVER_QUERY_LIMIT"

"error_message":"Keyless access to Google Maps Platform is deprecated. Please use an API key with all your API calls to avoid service interruption. For further details please refer to http://g.co/dev/maps-no-account","routes":[],"status":"OVER_QUERY_LIMIT"

我的清单中有这个

<meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="MY_GOOGLE_MAPS_API_KEY" />

此外,此API KEY已在我的API CONSOLE中启用",并且仅限于Google Maps Android SDK和Directions API.我的Google API控制台也启用了结算功能,但有时仍然会出现此错误.

Also, this API KEY 'enabled' in my API CONSOLE and it is restricted to Google Maps Android SDK and Directions API. I also have billing enabled for my Google API CONSOLE but I still get this error sometimes.

推荐答案

自2018年6月11日起,Google开始强制使用API​​密钥.无键使用将导致体验下降,或出现OVER_DAILY_LIMIT和OVER_QUERY_LIMIT之类的错误.

Since June 11th 2018, Google began enforcing the use of API keys. Keyless usage will result in a degraded experience, or an error like OVER_DAILY_LIMIT and OVER_QUERY_LIMIT.

来源:来自Google Maps Platform的重要更新

像这样将API密钥放入URL中是一个很好的解决方案:

Putting the API Key in the URL like this is a good solution:

String url = "https://maps.googleapis.com/maps/api/directions/"+output+"?"+parameters + "&key=" + MY_API_KEY

但是请确保您的密钥限制配置正确.如果您将密钥限制为您的应用程序,则可能无法使用,因为通过HTTP发出的请求与您的IP地址相关.这意味着,即使您已经正确配置了Android应用和清单,也可能会产生ACCESS_DENIED.可以通过更改限制来验证这一点.

But be sure that your key restrictions are well configured. If you have restricted the Key to your app, it may not work because the request made via HTTP are related with your IP address. Meaning that even if you have correctly configured your Android App and manifest, it may result with an ACCESS_DENIED. This can be verified by changing your restriction.

不受测试限制的示例:

Example of no restriction for testing purpose:

有关API密钥和限制的更多详细信息:获取密钥的快速指南

For more details about API key and restrictions: Quick guide to getting a key

这篇关于不建议使用无密钥访问Google Maps Platform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆