Google Awareness API,无效的API密钥,崩溃 [英] Google Awareness API, Invalid API key, Crash
问题描述
这是我第一次尝试创建android应用程序.在尝试使用Google提供的Awareness API时,我在logcat中收到一个SecurityException并收到错误消息:
This is my first attempt at creating an android application. In trying to use the Awareness API provided by Google I receive a SecurityException in logcat, and the error:
程序包的无效API密钥= com.example.android.project.收到的状态码= 12".
"Invalid API Key for package = com.example.android.project. Status code received = 12".
意味着,mGoogleApiClient.connect()会使应用每次崩溃.反正有什么要知道状态码是什么意思?
Meaning, mGoogleApiClient.connect() causes the app to crash every time. Is there anyway to know what the status code means?
[BaseServerTask]Server task (PingTask) got error statusCode=403.
com.android.volley.AuthFailureError
at com.android.volley.toolbox.BasicNetwork.performRequest(:com.google.android.gms:32)
at lbf.performRequest(:com.google.android.gms:3)
at com.android.volley.NetworkDispatcher.run(:com.google.android.gms:11)
07-01 15:54:24.303 4839-19074/? E/ctxmgr: [ContextManager3PCredentialsVerifier]Failed ping response: network status=12
07-01 15:54:24.304 4839-19081/? E/AbstractServiceBroker: Getting service failed
java.lang.SecurityException: Invalid API Key for package = com.example.android.project. Status code received = 12
at cpm.a(:com.google.android.gms:19)
at cpp.a(:com.google.android.gms:46)
at ktv.a(:com.google.android.gms:41)
at kwh.onTransact(:com.google.android.gms:8)
at android.os.Binder.transact(Binder.java:507)
at bxh.onTransact(:com.google.android.gms:2)
at android.os.Binder.execTransact(Binder.java:573)
07-01 15:54:24.520 19508-19508/com.example.android.project E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.project, PID: 19508
java.lang.SecurityException: Invalid API Key for package = com.example.android.project. Status code received = 12
at android.os.Parcel.readException(Parcel.java:1693)
at android.os.Parcel.readException(Parcel.java:1646)
at com.google.android.gms.common.internal.zzax.zza(Unknown Source)
at com.google.android.gms.common.internal.zzd.zza(Unknown Source)
at com.google.android.gms.internal.zzbcj.zzpV(Unknown Source)
at com.google.android.gms.internal.zzbcn.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:428)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at com.google.android.gms.internal.zzbgx.run(Unknown Source)
at java.lang.Thread.run(Thread.java:762)
此错误没有道理,因为我在开发人员控制台中将API密钥设置为无限制,希望它可以解决此问题,即未锁定到任何项目,并且仍然无法正常工作.并在控制台中启用了API.
This error does not make sense, because in the Developer Console I set the API key to have no restriction hoping it would solve this, i.e. not locked to any project and it still will not work. And the API is enabled in the console.
我尝试了其他主题的建议:无法连接到Google API CLient?,尝试接收错误与Google意识服务等连接.但是问题仍然存在.
I've tried suggestions from other threads: Unable to connect to Google API CLient?, Receiving error when trying to connect with Google Awareness services, etc. But the problem remains.
public class MainActivity extends AppCompatActivity implements
GoogleApiClient.OnConnectionFailedListener,
GoogleApiClient.ConnectionCallbacks {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Connect to Awareness API
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Awareness.API)
.build();
mGoogleApiClient.connect(); // the app crashes here
}
}
最后我的AndroidManifest:
Lastly my AndroidManifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.project">
<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="@drawable/appicon"
android:label="@string/app_name"
android:roundIcon="@drawable/appicon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.awareness.API_KEY"
android:value="MY_API_KEY"/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="MY_API_KEY"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
我不知道该怎么办,有人有什么建议吗?
I don't know what to do, does anyone have any suggestions?
我正在三星银河S6(Android版:7.0)上对此进行测试
I'm testing this on an Samsung Galaxy S6, Android Version: 7.0
推荐答案
似乎您的API_KEY在AndroidManifest中的设置不正确: 请注意,正确的软件包名称为
It seems like your API_KEY is set up incorrectly in the AndroidManifest: note that the right package name is
"com.google.android.awareness.API_KEY"
"com.google.android.awareness.API_KEY"
而不是
"com.google.awareness.API_KEY"
"com.google.awareness.API_KEY"
如您所愿. 请参见 https://developers.google.com/awareness/android-api/get开始
这篇关于Google Awareness API,无效的API密钥,崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!