当我的应用尝试使用Google Maps API时,一旦尝试访问Google Map API数据,我将收到以下logcat错误(向右滚动以查看好东西!):
02-02 15:39:35.329 23868-24511/com.somepackage.name E/Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
02-02 15:39:35.339 23868-24511/com.somepackage.name E/Google Maps Android API: Ensure that the following correspond to what is in the API Console:
API Key: AI~~~~~~~~~~~~~~~~~~~~~~~~~~ZwmI
Package Name: com.somepackage.name
Certificate Fingerprint: 50:~~~~~~~~~~~~~~~~~~~~:D5
这是带有指纹和API密钥的Google Developers Support Console的图像(是的,它们确实匹配!)。我还等待Google服务器更新(根据Dox的要求是5分钟;我已经等了几个小时)。
这是我项目的主要AndroidManifest.xml(为简洁起见进行了编辑):
<?xml version="1.0" encoding="utf-8"?>
...
<!--
The following two permissions are not required to use
Google Maps Android API v2, but are recommended.
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
...
<!--The key to use Google's map API -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIz~~~~~~~~~~~~~~~~~~~~~~~~~~~~wmI"/>
<activity
...
</activity>
...
</application>
我拥有Google的高级支持帐户,但到目前为止无法与他们联系。有谁知道为什么我会遇到此授权失败?
After many hours, I figured out the answer plus one very important gotcha!
I need to re-explain as details I didn't know where important are actually paramount.
I inherited this project, so its history was unknown. Originally the program used the free version of Google Maps, which worked fine. Since this is a large company, they went ahead and paid for the full premium subscription service. Programmers added the new libraries and made the few code modifications to use those libraries.
But they still used the original (free) authorization key. This caused Google's servers to continue to treat the data as if it were a free version.
No one noticed this because the free Goole Maps API only has issues after some number (2500?) of API calls in one day. Our traffic only recently became high enough for this to be an issue. (After the limit, Google API sends an error message instead of data.)
Consequently any changes I made seemed to have no effect. And changing the keys in the code caused the authentication errors (see in question).
I had to make a new authentication key using the new premium libraries and console. This changed the Google server which of course caused all versions of the app already in existence to cease functioning!
The new authentication key, placed in the manifest, gets recognized by the Google API and everything works, yay! But we still need to release a new version in the Google Store.
文档DID NOT WORK中列出的AndroidManifest.xml命令:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AI............................mI"/>
这是实际可行的正确名称:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AI............................mI" />
但是在测试时,我仍然遇到各种错误。为什么?因为android设备会维护身份验证密钥的缓存。清除数据(最好是卸载)会清除这些缓存。现在一切正常,是的。
寓意:与API密钥,认证,证书和打交道时什么相似,卸载每一次!:)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句