2

我有一个我不理解 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();
}
4

1 回答 1

0

我认为问题在于 id 设置为 new Date().toString() ,其中包含空格并且 API 不吃那个。用lodash替换空格,它会起作用: .setId(new Date().toString()).replace(/\W/gi, "_")

于 2014-07-21T20:40:14.310 回答