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

查看:65
本文介绍了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?

推荐答案

许多小时后,我想出了答案,外加一个非常重要的 gotcha!

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).

我必须使用新的高级库和控制台创建新的身份验证密钥.这改变了Google服务器,这当然导致已经存在的所有版本的应用程序停止运行!

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 Store中发布新版本.

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​" />

Gotcha#2

但是在测试时,我仍然遇到各种各样的错误.为什么?因为android设备会维护身份验证密钥的缓存.清除数据(或者最好是卸载)会清除这些缓存.现在,一切正常,是的.

道德:在处理API密钥,身份验证,证书和类似的所有内容时,请每次卸载!:)

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

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

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