我正在尝试使用GoogleApiClient编写"创建图像"使用Moment的行动(google play-services:7.0.0)。 初始化api客户端:
GoogleApiClient.Builder plusClientBuilder = new GoogleApiClient.Builder(context, this, this);
String accountName = prefs.getString(KEY_GPLUS_ACCOUNT_NAME, null);
if (!TextUtils.isEmpty(accountName)) {
plusClientBuilder.setAccountName(accountName);
}
plusClientBuilder.addScope(Plus.SCOPE_PLUS_LOGIN)
.addScope(Plus.SCOPE_PLUS_PROFILE)
.addScope(new Scope("https://www.googleapis.com/auth/plus.profile.emails.read"));
Plus.PlusOptions plusOptions = Plus.PlusOptions.builder().addActivityTypes(new String[]{"http://schemas.google.com/AddActivity", "http://schemas.google.com/CommentActivity", "http://schemas.google.com/CreateActivity"}).build();
plusClientBuilder.addApi(Plus.API, plusOptions);
GoogleApiClient mPlusClient = plusClientBuilder.build();
然后在onConnect()上尝试编写Add moment:
@Override
public void onConnected(Bundle arg0) {
ItemScope authUser = new ItemScope.Builder().setType("http://schema.org/Person").setName(username).build();
List<ItemScope> author = new ArrayList<>();
author.add(authUser);
ItemScope target = new ItemScope.Builder().setUrl("http://example.com/photo?id=photoId").build();
String scopeUrl = "http://example.com/photo/google
itemType=http://schema.org/ImageObject&name="+title+"&image="+imgUrl+"&description="+desc+"&creator="+userName;
ItemScope.Builder scopeBuilder = new ItemScope.Builder().
setUrl(scopeUrl).
setType("http://schema.org/ImageObject").
setName(title).
setImage(imgUrl).
setDescription(desc).
setThumbnailUrl(thumbUrl).
setAuthor(author);
Moment moment = new Moment.Builder().setType("http://schemas.google.com/CreateActivity").setTarget(target).setResult(scopeBuilder.build()).build();
Plus.MomentsApi.write(mPlusClient, moment).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(com.google.android.gms.common.api.Status result) {
L.i("GPlus", "write moment" + result);
}
});
}
我在ResultCallback上获得 {statusCode = INTERNAL_ERROR,resolution = null} 。 我已在Google Developers Console中启用Google+ API,创建OAuth 2.0客户端ID,.apk文件通过公共证书签名。 OAuth成功通过。
我做错了吗?这一刻类型是否需要其他一些属性?