Reputation: 449
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...
Upvotes: 1
Views: 1007
Reputation: 15569
The problem is that currently targets can have either a URL or detailed properties but not both. If you provide a URL Google will fetch all the information from the schema.org markup and doesn't allow other properties.
So you will have to remove the .setUrl(mapLing)
from your code and it should work.
Or alternatively you create a page with all the meta information you want included as schema.org markup, and use the URL of that page as target with no other information added in the request body.
There's an open issue for that here: https://code.google.com/p/google-plus-platform/issues/detail?id=485
Also, last time I checked some moment types require some properties to be included to work. For example CheckInActivity requires http://schema.org/PostalAddress
and/or http://schema.org/GeoCoordinates
either in the request body or included in the target URL markup. Unfortunately there isn't much documentation about what fields are required for what moment types so you will have to experiment there a little bit.
Upvotes: 5