Android:Google 地图 Android API:授权失败 [英] Android: Google Maps Android API: Authorization failure

查看:27
本文介绍了Android:Google 地图 Android API:授权失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我的应用尝试使用 Google Maps API 时,我会在尝试访问 Google Map API 数据时立即收到以下 logcat 错误(向右滚动以查看好东西!):

When my app tries to use the Google Maps API, I get the following logcat error as soon as I try to access Google Map API data (scroll right to see the good stuff!):

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 分钟;我已经等了几个小时).

Here is an image of the Google Developers Support Console with the Fingerprint and the API Key (and yes, they DO match!). I have also waited for the Google servers to update (5 minutes according to the dox; I have waited hours).

这是我项目的主要 AndroidManifest.xml(为简洁起见进行了编辑):

And here is my project's primary AndroidManifest.xml (edited for brevity):

<?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 的高级支持帐户,但目前无法联系到他们.有谁知道为什么我会收到此授权失败的消息?

I have a Premium Support account with Google, but have been unable to contact them so far. Does anyone have any idea why I'm getting this Authorization Failure?

推荐答案

经过几个小时,我找到了答案以及一个非常重要的问题!

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.

我继承了这个项目,所以它的历史是未知的.最初该程序使用免费版的 Google 地图,效果很好.由于这是一家大公司,他们继续支付了完整的高级订阅服务.程序员添加了新库并进行了少量代码修改以使用这些库.

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.

但他们仍然使用原始(免费)授权密钥.这导致 Google 的服务器继续将数据视为免费版本.

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.

没有人注意到这一点,因为免费的 Goole Maps API 仅在一天内调用了一定数量(2500?)API 后才会出现问题.我们的流量最近才变得足够高,以至于这成为一个问题.(在限制之后,Google API 会发送错误消息而不是数据.)

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!

放置在清单中的新身份验证密钥被 Google API 识别,一切正常,耶!但我们仍然需要在 Google 商店中发布新版本.

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.

文档中列出的 AndroidManifest.xml 命令无效:

The AndroidManifest.xml command that is listed in the docs DID NOT WORK:

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

这是实际有效的正确名称:

This is the correct name that actually works:

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AI............................mI​" />

陷阱 #2

但是在测试的时候,还是出现了各种各样的错误.为什么?因为 android 设备维护身份验证密钥的缓存.清除数据(或更好的卸载)清除了这些缓存.现在一切正常,是的.

道德:在处理 API 密钥、身份验证、证书和任何类似的东西时,每次都卸载!:)

Moral: when dealing with API keys, authentication, certificates, and anything similar, uninstall EVERY TIME! :)

这篇关于Android:Google 地图 Android API:授权失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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