我遇到了游戏服务的问题。对于一个简单的连接,我得到:
07-14 00:28:08.394 28271 28271 I gobandroid: connected
07-14 00:28:08.783 19165 19206 E Volley : [1562] BasicNetwork.performRequest: Unexpected response code 401 for https://www.googleapis.com/games/v1/applications/played
07-14 00:28:08.789 19165 28324 W GameAgent: Volley error when reporting played
07-14 00:28:08.789 19165 28324 W GameAgent: com.android.volley.AuthFailureError
07-14 00:28:08.789 19165 28324 W GameAgent: at com.android.volley.toolbox.BasicNetwork.performRequest(:com.google.android.gms:159)
07-14 00:28:08.789 19165 28324 W GameAgent: at ipb.performRequest(:com.google.android.gms:64)
07-14 00:28:08.789 19165 28324 W GameAgent: at com.android.volley.NetworkDispatcher.run(:com.google.android.gms:113)
这个初始化代码
mGoogleApiClient = GoogleApiClient.Builder(activity).addConnectionCallbacks(object : GoogleApiClient.ConnectionCallbacks {
override fun onConnected(bundle: Bundle?) {
Log.i("connected")
}
override fun onConnectionSuspended(i: Int) {
// Attempt to reconnect
mGoogleApiClient!!.connect()
}
}).addApi(Games.API).addScope(Games.SCOPE_GAMES).build()
这是相关版本:
com.google.apis:google-api-services-games:v1-rev197-1.22.0
这也在日志中,也许是相关的:
07-14 14:39:17.827 1736 4963 W GamesServiceBroker: Client connected with SDK 8487000, Services 9256436, and Games 37230036
07-14 14:39:17.943 1736 2302 V BaseAuthAsyncOperation: All scopes had been granted in the past, skip access token fetching
07-14 14:39:17.951 1012 1012 I Auth : [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
07-14 14:39:17.952 1012 1012 I Auth : [AuthDelegateWrapper] Service intent: Intent { cmp=com.google.android.gms/.auth.account.authenticator.DefaultAuthDelegateService }.
07-14 14:39:17.973 1012 1022 D GoogleCertificatesImpl: Fetched 318 Google certificates
07-14 14:39:18.023 1736 2302 V BaseAuthAsyncOperation: access token request successful
07-14 14:39:18.077 613 1644 W AppOps : Bad call: specified package com.google.android.play.games under uid 10230 but it is really 10066
答案 0 :(得分:1)
请尝试使用排球库进行HTTP身份验证。
这些SO帖子中提供的解决方案和解释 - com.android.volly.AuthFailureError in making basic volly POST request to a django server和How does one use Basic Authentication with Volley on Android?可能有所帮助。快乐的编码! :)
答案 1 :(得分:1)
我认为这可能是您Google API key
的问题;
生成API密钥时,请选择 Android-App ,而不是 web-app 。
希望这会对你有帮助!