我正在尝试使用 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();
这是onConnected:
public void onConnected() {
//Log.d(tag,"onConnected()...");
googlePlusUserEmail = mPlusClient.getAccountName();
Log.d(tag, "googlePlusUserEmail = " + googlePlusUserEmail);
}
调用“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);
但是,如果我理解正确,我无法将图像“附加”到 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);
}
检查此答案后,我启用了 GooglePlatform 的详细调试:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
不幸的是,当我尝试写它返回此日志的那一刻:
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): }
正如我从这个答案中看到的那样,这不应该是凭据问题,因为我可以成功使用 +1 和 PlusShare 功能。我也浏览了谷歌文档here,特别是CheckInActivity here,但仍然没有运气。如果有人可以对为什么响应为 400 提出建议,那就太好了。
EDIT1:在以下 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());
}
好消息是 400 错误响应代码消失了 :-),但是我的个人资料上什么也没有出现 :-(。我会处理它并很快更新...