PlusClient.writeMoment(moment)返回500(Android PlusClient Api)

时间:2013-06-04 12:31:44

标签: android

我有一个我不理解的函数,它与PlusClient librairy的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();
}

1 个答案:

答案 0 :(得分:0)

我认为问题是id被设置为new Date()。toString(),其中包含空格而API不会吃掉它。用lodash替换空格,它将起作用:.setId(new Date()。toString())。replace(/ \ W / gi,“_”)