Dim*_*ris 1 android google-plus
我正在尝试使用PlusClient在Google+用户的个人资料中使用"时刻"编写位置签到.这是我初始化客户端的方式:
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/CheckInActivity")
.setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE).build();
Run Code Online (Sandbox Code Playgroud)
这是onConnected:
public void onConnected() {
//Log.d(tag,"onConnected()...");
googlePlusUserEmail = mPlusClient.getAccountName();
Log.d(tag, "googlePlusUserEmail = " + googlePlusUserEmail);
}
Run Code Online (Sandbox Code Playgroud)
在调用"mPlusClient.connect();"之后 连接成功完成.我有+1按钮,工作正常,我还设法使用PlusShare发布用户的个人资料:
String mapLing = "https://maps.google.com/maps?q=" + myLatitude + "," + myLongitude + "&hl=en";
String description = "Hello!";
Intent shareIntent = new PlusShare.Builder()
.setType("text/plain")
.setText(description)
.setContentUrl(Uri.parse(mapLing))
.getIntent();
startActivityForResult(shareIntent, 0);
Run Code Online (Sandbox Code Playgroud)
但是,如果我理解正确,我无法用PluShare"附加"图像,所以我尝试使用Moments,如下所示:
String mapLing = "https://maps.google.com/maps?q=" + myLatitude + "," + myLongitude + "&hl=en";
String description = "Hello!";
//build the item scope
ItemScope checkInLocation = new ItemScope.Builder()
.setId(googlePlusUserId) //do I need it?
.setType("http://schema.org/Place") //tried also with "Thing" instead of Place, but no luck
.setName(mOverlays.get(index).getSnippet() + " - " + mOverlays.get(index).getTitle())
.setUrl(mapLing)
.setImage("http://www.mysite.com/images/icon.png")
.setDescription(description)
.build();
Moment moment = new Moment.Builder()
.setType("http://schemas.google.com/CheckInActivity")
.setTarget(checkInLocation).build();
if (mPlusClient.isConnected()) {
Log.d(tag, "writeMoment...");
mPlusClient.writeMoment(moment);
}
Run Code Online (Sandbox Code Playgroud)
检查此答案后,我启用了GooglePlatform的详细调试:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试写下它返回此日志时:
05-22 01:08:01.908: E/Volley(3611): [29] il.a: Unexpected response code 400 for https://www.googleapis.com/plus/v1/people/me/moments/vault
05-22 01:08:01.918: D/GooglePlusPlatform(3611): Unexpected response code (400) when requesting: writeMoment
05-22 01:08:01.918: D/GooglePlusPlatform(3611): Error response: {
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "error": {
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "errors": [
05-22 01:08:01.918: D/GooglePlusPlatform(3611): {
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "domain": "global",
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "reason": "invalid",
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "message": "Invalid Value"
05-22 01:08:01.918: D/GooglePlusPlatform(3611): }
05-22 01:08:01.918: D/GooglePlusPlatform(3611): ],
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "code": 400,
05-22 01:08:01.918: D/GooglePlusPlatform(3611): "message": "Invalid Value"
05-22 01:08:01.918: D/GooglePlusPlatform(3611): }
05-22 01:08:01.918: D/GooglePlusPlatform(3611): }
Run Code Online (Sandbox Code Playgroud)
正如我从这个答案中看到的那样,它不应该是凭证问题,因为我可以成功使用+1和PlusShare功能.我也通过谷歌文档了这里,并专门对CheckInActivity 这里,但仍没有运气.如果有人可以就响应为400的原因提出建议,那就太好了.
编辑1:在下面的Scarygami和Lee的建议之后,我尝试使用以下代码添加最简单的时刻:
ItemScope checkInLocation = new ItemScope.Builder()
.setId("1234545")
.setName("MyName")
//.setUrl(mapLing) //link removed
.setImage("http://www.mysite.com/images/icon.png")
.setDescription("MyDescription")
.setType("http://schema.org/Thing")
.build();
Moment moment = new Moment.Builder()
.setType("http://schemas.google.com/AddActivity")
.setTarget(checkInLocation).build();
if (mPlusClient.isConnected()) {
Log.d(tag, "writeMoment...");
mPlusClient.writeMoment(moment);
Log.d(tag, "moment.getResult() = " + moment.getResult());
}
Run Code Online (Sandbox Code Playgroud)
好消息是400错误响应代码消失了:-),但是我的个人资料中没有出现任何内容:-(.我将继续处理并尽快更新...
问题是目前的目标可以有URL或详细属性,但不能同时具有两者.如果您提供URL,Google将从schema.org标记中获取所有信息,并且不允许其他属性.
所以你必须.setUrl(mapLing)从你的代码中删除它,它应该工作.
或者,您可以创建一个页面,其中包含您希望包含在schema.org标记中的所有元信息,并使用该页面的URL作为目标,而请求正文中不会添加其他信息.
这里有一个未解决的问题:https://code.google.com/p/google-plus-platform/issues/detail?id = 485
此外,上次我检查了一些时刻类型需要包含一些属性才能工作.例如,CheckInActivity需要http://schema.org/PostalAddress和/或http://schema.org/GeoCoordinates在请求正文中或包含在目标URL标记中.遗憾的是,没有太多关于哪些字段类型需要哪些字段的文档,所以你必须在那里进行一些实验.
| 归档时间: |
|
| 查看次数: |
1001 次 |
| 最近记录: |