I am trying to use the PlusClient to write a location check-in using a "moment" on a Google+ user's profile. This is how I initialize the client:
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();
Here is the onConnected:
public void onConnected() {
//Log.d(tag,"onConnected()...");
googlePlusUserEmail = mPlusClient.getAccountName();
Log.d(tag, "googlePlusUserEmail = " + googlePlusUserEmail);
}
After calling "mPlusClient.connect();" the connection is done successfully. I have a +1 button that works fine, and I have also managed to post on user's profile using the 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);
However, if I have understand correctly I cannot "attach" an image with the PluShare, so I tried to use the Moments, like this:
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);
}
After checking this answer, I enabled the Verbose debug of GooglePlatform:
adb shell setprop log.tag.GooglePlusPlatform VERBOSE
Unfortunately, when I try to write the moment it returns this log:
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): }
As I have also seen from this answer, it should not be a credentials problem, since I can successfully use the +1 and the PlusShare functions. I have also gone through the Google documentation here and specifically on the CheckInActivity here, but still no luck. If anyone could have a suggestion on why the response is 400, it would be great.
EDIT1: After Scarygami's and Lee's suggestions below, I have tried to add the simplest moment using the following code:
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());
}
The good news is that the 400 error response code is gone :-), however nothing appears on my profile :-(. I'll work on it and update soon...