我的 android 应用程序正在使用 Google+ API 将用户连接到这个社交网络并记录其中的活动。
我的代码很简单,我复制了示例代码以在此处编写评论活动: https ://developers.google.com/+/mobile/android/app-activities
monPlusClient = new PlusClient.Builder(this,
new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onDisconnected() {
Log.d(TAG_DEBUG, "monPlusClient, onDisconnected");
}
@Override
public void onConnected(Bundle connectionHint) {
String accountName = monPlusClient.getAccountName();
Log.d(TAG_DEBUG, "monPlusClient, onConnected : " + accountName);
String targetUrl = "https://developers.google.com/+/mobile/android/getting-started";
ItemScope rating = new ItemScope.Builder()
.setType("http://schema.org/Rating")
.setRatingValue("100").setBestRating("100")
.setWorstRating("0").build();
ItemScope result = new ItemScope.Builder()
.setType("http://schema.org/Review")
.setName("A Humble Review of Widget")
.setUrl("https://developers.google.com/+/web/snippet/examples/review")
.setDescription("It is amazingly effective")
.setReviewRating(rating).build();
ItemScope target = new ItemScope.Builder().setUrl(targetUrl).build();
Moment moment = new Moment.Builder()
.setType("http://schemas.google.com/ReviewActivity")
.setTarget(target).setResult(result)
.build();
monPlusClient.writeMoment(moment);
Log.d(TAG_DEBUG, "ActiviteListeVoyages, monPlusClient, writeMoment effectué");
Toast.makeText( ActiviteListeVoyages.this,
ActiviteListeVoyages.this.getResources().getString(R.string.textesauvegarde),
Toast.LENGTH_LONG).show();
},
new GooglePlayServicesClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult resultat) {
Log.d(TAG_DEBUG, "monPlusClient, onConnectionFailed");
if (resultat.hasResolution()) {
try {
resultat.startResolutionForResult(
ActiviteListeVoyages.this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
}
}
// Save the result and resolve the connection failure
// upon a user click.
ResultatConnexion = resultat;
}
}).setScopes(Scopes.PLUS_LOGIN)
.setVisibleActivities("http://schemas.google.com/AddActivity",
"http://schemas.google.com/DiscoverActivity",
"http://schemas.google.com/ReviewActivity").build();
当我执行应用程序时,我可以看到连接正常,但稍等片刻,logcat 显示:
08-31 17:04:08.410: W/ejk(528): Authentication error: Unable to respond to any of these challenges: {bearer=WWW-Authenticate: Bearer realm="https://www.google.com/accounts/AuthSubRequest", error=invalid_token}
08-31 17:04:08.410: I/qtaguid(528): Failed write_ctrl(u 64) res=-1 errno=22
08-31 17:04:08.410: I/qtaguid(528): Untagging socket 64 failed errno=-22
08-31 17:04:08.440: W/NetworkManagementSocketTagger(528): untagSocket(64) failed with errno -22
08-31 17:04:08.450: E/Volley(528): [71] je.a: Unexpected response code 401 for https://www.googleapis.com/plus/v1/people/me/moments/vault
08-31 17:04:08.450: D/GooglePlusPlatform(528): Unexpected response code (401) when requesting: writeMoment
08-31 17:04:08.470: I/GooglePlusPlatform(528): {"code":401,"errors":[{"message":"Unauthorized","domain":"global","reason":"unauthorized"}]}
08-31 17:04:08.480: D/dalvikvm(528): GC_CONCURRENT freed 634K, 12% free 8315K/9415K, paused 25ms+5ms, total 73ms
08-31 17:04:08.520: D/SyncManager(272): failed sync operation xxxxxxxxxx@gmail.com (com.google), com.google.android.gms.plus.action, USER, earliestRunTime 78281280, SyncResult: stats [ numIoExceptions: 1]
08-31 17:04:15.489: D/Finsky(5255): [1] 5.onFinished: Installation state replication succeeded.
我在 Google API 控制台中注册了我的应用程序。我还有另一个可以在 Google+ 中写备忘录的应用程序,这两个清单是相似的。
我忘记了什么?
在多次撤销 G+ 令牌并在 API 控制台中重新创建客户端 ID 后,该错误现在出现代码 500 错误:
09-03 22:43:41.450: D/GooglePlusPlatform(1146): Unexpected response code (500) when requesting: writeMoment
09-03 22:43:41.460: I/GooglePlusPlatform(1146): {"code":500}
09-03 22:43:43.460: D/SyncManager(272): failed sync operation xxxxxxxx@gmail.com (com.google), com.google.android.gms.plus.action, USER, earliestRunTime 357855202, SyncResult: stats [ numIoExceptions: 1]
以下是用户进行身份验证时的设备屏幕: