Google+的Android的API PlusClient writeMoment做什么 [英] Google+ android API PlusClient writeMoment is doing nothing
问题描述
为了实现在Android应用程序的社交功能,我尝试使用PlusClient级的writeMoment的方法,但没有任何反应。我能够获得与PlusClient成功连接,并写深层链接的帖子我的应用程序。
下面是我的code,当我打开了Google+连接:
monPlusClient =新PlusClient.Builder(这一点,
新GooglePlayServicesClient.ConnectionCallbacks(){
@覆盖
公共无效onConnected(){
plusencours = FALSE;
串帐户名= monPlusClient.getAccountName();
//我们已经解决了所有连接错误。
Toast.makeText(
ActiviteAfficher.this,
用户名
+
+ ActiviteAfficher.this
.getResources()
.getString(
R.string.texteconnexion)
Toast.LENGTH_LONG).show();
// Log.d(TAG_DEBUG,帐户名+连接);
}
@覆盖
公共无效onDisconnected(){
plusencours = FALSE;
// Log.d(TAG_DEBUG,断开连接);
}
},新GooglePlayServicesClient.OnConnectionFailedListener(){
@覆盖
公共无效onConnectionFailed(ConnectionResult结果){
如果(resultat.hasResolution()){
尝试 {
resultat.startResolutionForResult(
ActiviteAfficher.this,
REQUEST_ code_RESOLVE_ERR);
}赶上(SendIntentException E){
plusencours = TRUE;
monPlusClient.connect();
}
}
//保存结果,并解决连接失败
//当用户点击。
mConnectionResult = resultat;
}
})
.setVisibleActivities(http://schemas.google.com/AddActivity
http://schemas.google.com/DiscoverActivity)
.setScopes(Scopes.PLUS_LOGIN,Scopes.PLUS_PROFILE).build();
和这里是我的code当我用writeMoment:
ItemScope目标=新ItemScope.Builder()
.setId(monSujet.getMid())
.setName(
monSujet.getName()+ -
+ monSujet.getNotablename())
.setDescription(dialoguedescription).setImage(urlimage)
.setType(http://schema.org/Person).build();
每时每刻=新Moment.Builder()
.setType(http://schemas.google.com/AddActivity)
.setTarget(目标).build();
如果(monPlusClient.isConnected()){
monPlusClient.writeMoment(时刻);
}
了解logcat的困难对我来说:
12月5号至九日:00:32.380:I / ElegantRequestDirector(27290):I / O异常(org.apache.http.NoHtt presponseException)处理请求时抓到:目标服务器无法响应
十二月5日至9日:00:32.380:I / ElegantRequestDirector(27290):重试请求
十二月5日至9日:00:33.000:E /排球(27290):[3428] BasicNetwork.performRequest:意外的响应code 400 https://www.googleapis.com/plus/v1/people/me/moments /金库
十二月5日至9日:00:33.050:D / SyncManager(295):未能同步操作XXXXXXX@gmail.com(com.google),com.google.android.gms.plus.action,USER,earliestRunTime 140603923,SyncResult:统计[numIoExceptions:1]
十二月5日至9日:00:33.050:D / SyncSetupManager(16157)的setState:SYNC = TRUE,wantedSyncState =真
十二月5日至9日:00:33.090:D / SyncSetupManager(16157):启用同步
如果您在写作时应用程序的活动调试问题的问题,您应该尝试启用调试的GooglePlusPlatform:
亚行外壳setprop log.tag.GooglePlusPlatform VERBOSE
这也是在这里描述 - 的https://developers.google.com/+/mobile/android/getting-started#frequently_asked_questions
运行您的code调试启用写入以下为logcat的:
D / GooglePlusPlatform(8133):意外的响应$ C $请求时,C(400):writeMoment
D / GooglePlusPlatform(8133):错误响应:{
D / GooglePlusPlatform(8133):错误:{
D / GooglePlusPlatform(8133):错误:
D / GooglePlusPlatform(8133):{
D / GooglePlusPlatform(8133):域:全球性,
D / GooglePlusPlatform(8133):理由:badRequest
D / GooglePlusPlatform(8133):消息:缺少元数据字段:http://schema.org/url
D / GooglePlusPlatform(8133):}
D / GooglePlusPlatform(8133):]
D / GooglePlusPlatform(8133):code:400,
D / GooglePlusPlatform(8133):消息:缺少元数据字段:http://schema.org/url
D / GooglePlusPlatform(8133):}
D / GooglePlusPlatform(8133):}
您不能没有提供它具有适当的标记(而不是一个明确的名称和说明)公共目标URL提供一个Person对象。与 http://schema.org/Thing 代替的 http://schema.org/Person 为我工作。
In order to implement social features in an android app, I try to use the "writeMoment" method of the "PlusClient" class, but nothing happens. I am able to get a successful connection with "PlusClient" and to write deep link posts with my app.
Here is my code when I open the Google+ connection :
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();
And here is my code when I use "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);
}
Understanding the logcat is difficult for me :
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
If you're having problems debugging issues while writing app activities, you should try enabling debug for GooglePlusPlatform:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
Which is also described here - https://developers.google.com/+/mobile/android/getting-started#frequently_asked_questions
Running your code with debugging enabled writes the following to 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): }
You cannot supply a Person object without supplying a public target URL which has appropriate markup (instead of an explicit name and description). Running your code with http://schema.org/Thing instead of http://schema.org/Person worked for me.
这篇关于Google+的Android的API PlusClient writeMoment做什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!