尝试连接Google Awareness服务时收到错误 [英] Receiving error when trying to connect with Google Awareness services

查看:241
本文介绍了尝试连接Google Awareness服务时收到错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用google的意识api,并将GoogleApiClient的实例注册为意识api,但我收到了一个我找不到的错误。

I'm trying to work with google's awareness api, and register instance of GoogleApiClient to awareness api, but i'm receiving an error which i can't find anywhere.

我遵循手册,并在api consule中启用了提醒服务。
https://developers.google.com/awareness/android-api /开始

I've followed the manual, and enabled awareness services in the api consule. https://developers.google.com/awareness/android-api/get-started

这就是我的清单的样子:

This is how my manifest looks like :

<?xml version="1.0" encoding="utf-8"?>
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.test.awarenesstests">

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

       <meta-data
        android:name="com.google.android.awareness.API_KEY"
        android:value="MY_KEY_GENERATED_IN_THE_DEVELOPER_CONSULE" />
    </application>

</manifest>

非常简单的注册:

Very straightforward registration :

 GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Awareness.API).build();
 googleApiClient.connect();

这是我收到的错误 - package = com.test.awarenesstests的无效API密钥。收到的状态代码= 6

This is the error i'm receiving - Invalid API Key for package = com.test.awarenesstests .Status code received = 6

请注意,在日志开始时会出现一些奇怪的情况,对Google服务进行ping并返回403,它看起来与最终错误有关。

Notice that there's something weird in the start of the log, a ping is made to google services and returning 403, it looks related to the final error.

07-10 15:35:50.745 29260-29490/? E/Volley: [6925] BasicNetwork.performRequest: Unexpected response code 403 for https://www.googleapis.com/usercontext/v1/controllerhub/ping
07-10 15:35:50.750 29260-29260/? E/ctxmgr: [BaseServerTask]Server task (PingTask) got error response.
                                           com.android.volley.AuthFailureError
                                               at com.android.volley.toolbox.BasicNetwork.performRequest(:com.google.android.gms:159)
                                               at ipb.performRequest(:com.google.android.gms:64)
                                               at com.android.volley.NetworkDispatcher.run(:com.google.android.gms:113)
07-10 15:35:50.755 29260-15589/? W/ctxmgr: [ContextManager3PCredentialsVerifier]Received a failed ping response with status code = 6
07-10 15:35:50.755 29260-29275/? E/AbstractServiceBroker: Getting service failed
                                                          java.lang.SecurityException: Invalid API Key for package = com.test.awarenesstests .Status code received = 6
                                                              at bti.a(:com.google.android.gms:109)
                                                              at btl.a(:com.google.android.gms:5046)
                                                              at iht.a(:com.google.android.gms:592)
                                                              at ikn.onTransact(:com.google.android.gms:824)
                                                              at android.os.Binder.execTransact(Binder.java:446)
07-10 15:35:50.756 9603-9603/com.test.awarenesstests D/AndroidRuntime: Shutting down VM
07-10 15:35:50.757 9603-9603/com.test.awarenesstests E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       Process: com.test.awarenesstests, PID: 9603
                                                                       java.lang.SecurityException: Invalid API Key for package = com.test.awarenesstests .Status code received = 6
                                                                           at android.os.Parcel.readException(Parcel.java:1546)
                                                                           at android.os.Parcel.readException(Parcel.java:1499)
                                                                           at com.google.android.gms.common.internal.zzu$zza$zza.zza(Unknown Source)
                                                                           at com.google.android.gms.common.internal.zzd.zza(Unknown Source)
                                                                           at com.google.android.gms.internal.zzqb$zzc.zzapi(Unknown Source)
                                                                           at com.google.android.gms.internal.zzqb$zzf.run(Unknown Source)
                                                                           at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:422)
                                                                           at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                           at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                                                                           at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                                                                           at com.google.android.gms.internal.zzrs.run(Unknown Source)
                                                                           at java.lang.Thread.run(Thread.java:818)


推荐答案

我有同样的问题。 在应用程序的 build.gradle 文件中检查 applicationId 。对我来说,我在API密钥上设置在console.developers.google.com上的applicationId和包名称并不相同。我想他们必须是一样的。修复了它为我工作的名称。我希望它能为你工作。

I had the same issue. Check the applicationId in your application's build.gradle file. For me the applicationId and the package name i setted on the console.developers.google.com at my API key were not the same. I guess they have to be the same. After fixing the names it worked for me. I hope it will work for you.

这篇关于尝试连接Google Awareness服务时收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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