Google Android API PlusClient writeMoment无所作为
作者:互联网
为了在android应用中实现社交功能,我尝试使用“ PlusClient”类的“ writeMoment”方法,但没有任何反应.我能够与“ PlusClient”成功建立连接,并使用我的应用编写深层链接.
这是我打开Google连接时的代码:
monPlusClient = new PlusClient.Builder(this,
new GooglePlayServicesClient.ConnectionCallbacks() {
@Override
public void onConnected() {
plusencours = false;
String accountName = monPlusClient.getAccountName();
// We've resolved any connection errors.
Toast.makeText(
ActiviteAfficher.this,
accountName
+ " "
+ ActiviteAfficher.this
.getResources()
.getString(
R.string.texteconnexion),
Toast.LENGTH_LONG).show();
// Log.d(TAG_DEBUG, accountName + " connected");
}
@Override
public void onDisconnected() {
plusencours = false;
// Log.d(TAG_DEBUG, "disconnected");
}
}, new GooglePlayServicesClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult resultat) {
if (resultat.hasResolution()) {
try {
resultat.startResolutionForResult(
ActiviteAfficher.this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
plusencours = true;
monPlusClient.connect();
}
}
// Save the result and resolve the connection failure
// upon a user click.
mConnectionResult = resultat;
}
})
.setVisibleActivities("http://schemas.google.com/AddActivity",
"http://schemas.google.com/DiscoverActivity")
.setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build();
这是我使用“ writeMoment”时的代码:
ItemScope target = new ItemScope.Builder()
.setId(monSujet.getMid())
.setName(
monSujet.getName() + " - "
+ monSujet.getNotablename())
.setDescription(dialoguedescription).setImage(urlimage)
.setType("http://schema.org/Person").build();
Moment moment = new Moment.Builder()
.setType("http://schemas.google.com/AddActivity")
.setTarget(target).build();
if (monPlusClient.isConnected()) {
monPlusClient.writeMoment(moment);
}
对我来说,了解logcat很难:
05-09 12:00:32.380: I/ElegantRequestDirector(27290): I/O exception (org.apache.http.NoHttpResponseException) caught when processing request: The target server failed to respond
05-09 12:00:32.380: I/ElegantRequestDirector(27290): Retrying request
05-09 12:00:33.000: E/Volley(27290): [3428] BasicNetwork.performRequest: Unexpected response code 400 for https://www.googleapis.com/plus/v1/people/me/moments/vault
05-09 12:00:33.050: D/SyncManager(295): failed sync operation XXXXXXX@gmail.com (com.google), com.google.android.gms.plus.action, USER, earliestRunTime 140603923, SyncResult: stats [ numIoExceptions: 1]
05-09 12:00:33.050: D/SyncSetupManager(16157): setState: sync = true, wantedSyncState = true
05-09 12:00:33.090: D/SyncSetupManager(16157): Enabling sync
解决方法:
如果您在编写应用程序活动时调试问题时遇到问题,则应尝试为GooglePlusPlatform启用调试功能:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
在此也进行了说明-https://developers.google.com/+/mobile/android/getting-started#frequently_asked_questions
在启用调试的情况下运行代码会将以下内容写入logcat:
D/GooglePlusPlatform(8133): Unexpected response code (400) when requesting: writeMoment
D/GooglePlusPlatform(8133): Error response: {
D/GooglePlusPlatform(8133): "error": {
D/GooglePlusPlatform(8133): "errors": [
D/GooglePlusPlatform(8133): {
D/GooglePlusPlatform(8133): "domain": "global",
D/GooglePlusPlatform(8133): "reason": "badRequest",
D/GooglePlusPlatform(8133): "message": "Missing metadata field: http://schema.org/url."
D/GooglePlusPlatform(8133): }
D/GooglePlusPlatform(8133): ],
D/GooglePlusPlatform(8133): "code": 400,
D/GooglePlusPlatform(8133): "message": "Missing metadata field: http://schema.org/url."
D/GooglePlusPlatform(8133): }
D/GooglePlusPlatform(8133): }
如果不提供具有适当标记(而不是显式名称和描述)的公共目标URL,则不能提供Person对象.使用http://schema.org/Thing而不是http://schema.org/Person运行代码对我来说很有效.
标签:android,google-plus 来源: https://codeday.me/bug/20191011/1894753.html