2013-06-04 40 views
2

我有一個bug,我不明白PlusMethod PlusClient librairy的寫法。 連接正常,PlusShare.Builder是確定的,寫的互動信息,發現朋友和所有的東西工作正常,但writeMoment返回:PlusClient.writeMoment(moment)會返回500(Android PlusClient Api)

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(); 
} 

回答

0

我認爲這個問題是ID設置爲新的Date()的toString(),它包含空格和API不會吃。用lodash替換空格,它將起作用:.setId(new Date()。toString())。replace(/ \ W/gi,「_」)