我正在尝试使用谷歌的感知 api,并将 GoogleApiClient 的实例注册到感知 api,但我收到了一个我在任何地方都找不到的错误。
我已按照手册进行操作,并在 api consule 中启用了感知服务。 https://developers.google.com/awareness/android-api/get-started
这就是我的清单的样子:
<?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>
非常简单的注册:
GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
.addApi(Awareness.API).build();
googleApiClient.connect();
这是我收到的错误 - 包的 API 密钥无效 = com.test.awarenesstests .Status code received = 6
请注意,日志开头有一些奇怪的东西,对 google 服务进行 ping 并返回 403,它看起来与最终错误有关。
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)