PlusClient ライブラリの writeMoment について理解できないバグがあります。接続は問題ありません。PlusShare.Builder は問題なく、インタラクティブな投稿を書いたり、友達を見つけたり、すべて正常に動作しますが、writeMoment は次のように返します。
06-04 14:04:36.869: E/Volley(939): [2914] il.a: Unexpected response code 500 for https://www.googleapis.com/plus/v1/people/me/moments/vault
06-04 14:04:36.869: D/GooglePlusPlatform(939): Unexpected response code (500) when requesting: writeMoment
06-04 14:04:36.869: D/GooglePlusPlatform(939): Error response: {
06-04 14:04:36.869: D/GooglePlusPlatform(939): "error": {
06-04 14:04:36.869: D/GooglePlusPlatform(939): "code": 500,
06-04 14:04:36.869: D/GooglePlusPlatform(939): "message": null
06-04 14:04:36.869: D/GooglePlusPlatform(939): }
06-04 14:04:36.919: D/SyncManager(25079): failed sync operation **** u0 (com.google), com.google.android.gms.plus.action, USER, earliestRunTime 479744535, SyncResult: stats [ numIoExceptions: 1]
私のコードは次のとおりです。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Build your GPlus Person:
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities(
"http://schemas.google.com/AddActivity",
"http://schemas.google.com/CommentActivity",
"http://schemas.google.com/DiscoverActivity")
.setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE)
.build();
//Others stuffs
そして、呼び出されるメソッドは次のとおりです。
void writeMomentInStream() {
Person owner = mPlusClient.getCurrentPerson();
ItemScope target = new ItemScope.Builder()
// Also, use ItemScope.setId() to create a unique application specific ID for the item you are writing.
// It should NOT be set as the Google+ user ID.
.setId(new Date().toString())
.setText("text")
.setDescription("description")
.setThumbnailUrl(owner.getImage().getUrl())
.setType("http://schema.org/Thing")
.build();
// Ensure in your new PlusClient.Builder(this, this, this).setVisibleActivities(
// "http://schemas.google.com/AddActivity", "http://schemas.google.com/ListenActivity").build()
// You have define the activity you want to add as your moment type
Moment moment = new Moment.Builder()
.setType("http://schemas.google.com/AddActivity")
.setTarget(target)
.build();
if(mPlusClient.isConnected()) {
mPlusClient.writeMoment(moment);
}else {Log.e(TAG, "writeMomentInStream called !!!!mPlusClient.isConnected()");
}
Toast.makeText(fragment.getActivity(), "Moment has been sent", Toast.LENGTH_SHORT).show();
}