2013-04-09 39 views
1

我想分享一些信息在谷歌加牆從我的application.and我試圖爲moment.insert,但得到400錯誤。有人可以幫我如何使用谷歌加在api中的用戶的流在java中發佈

@Override 
    public JSONObject getGooglePlusAddUseractivities(Object token) { 
    Token accessToken = (Token) token; 
    OAuthService service = createOAuthServiceForGooglePlus(); 
    OAuthRequest request = new  OAuthRequest(Method.POST,"https://www.googleapis.com/plus/v1/people/me/moments/vault"); 
    request.addQuerystringParameter("alt", "json"); 
    service.signRequest(accessToken, request); 
    JSONObject object=new JSONObject(); 
    try { 
    object.put("kind","plus#moment"); 
    object.put("type","http://schemas.google.com/AddActivity"); 
    JSONObject obj1=new JSONObject(); 
    obj1.put("kind", "plus#itemScope"); 
    obj1.put("url","https://plus.google.com/me"); 
    obj1.put("description","Sign up now to claim and redeem your credits while   shopping! "); 
    obj1.put("image","http://invite.png"); 
    obj1.put("contentUrl", "www.abcd.com"); 
    obj1.put("thumbnailUrl", "http://logo1_favicon.png"); 
    object.putOpt("target", obj1);; 
    }catch(Exception ex) { 
      ex.printStackTrace(); 
     } 
    request.addPayload(object.toString()); 
    request.addHeader("Content-Type", "application/json"); 
    System.out.println("request : "+request.getBodyContents()); 
    Response response = request.send(); 
    String responseBody = response.getBody(); 
    JSONObject googleJSON = null; 
    try { 
     googleJSON = new JSONObject(responseBody); 
    } 
    catch (JSONException e) { 
     System.out.println("can not create JSON Object"); 
    } 

得到400錯誤?任何人都可以告訴我.....哪裏錯了.. !!

回答

4

從文檔中不清楚,但不能同時提供target.url和大多數其他target元數據。目前在問題跟蹤系統中以bug 485的身份打開 - 請轉到此處並對問題進行明確排查,以確保它們正確地確定修復的優先級。

如果您刪除target.url值並添加一個target.id值,它應該工作。

(順便說一句,這不發佈用戶的信息流中,但將在自己的應用瞬間庫發佈一個應用活動。他們必須手動共享的活動,如果他們選擇。)

+0

thnx囚犯。我已經修復了這個私有靜態最終String AUTHORIZE_URL =「https://accounts.google.com/o/oauth2/auth?client_id=%s&redirect_uri=%s&response_type=code&request_visible_actions=http://schemas.google.com/ AddActivity&ACCESS_TYPE =離線「;我沒有在授權url中提及request_visible_actions。現在代碼正在工作,但不會在用戶的流上發佈。你能幫我嗎? – dinesh 2013-04-09 16:53:25

+0

我不完全確定你現在在說什麼。聽起來像是最好開始另一個問題。 – Prisoner 2013-04-09 19:10:35

4

在這個時候,無法以編程方式寫入用戶的Stream。作爲開發人員,您有兩種選擇:

  1. 編寫一個AppActivity(以前稱爲Moment),它將信息寫入Google,但不寫入Google+信息流。這些活動在plus.google.com/apps上可見,並且隨着時間的推移,Google將以其他方式使用這些活動。
  2. 創建一個用戶必須啓動的Interactive Interactive Share按鈕。但是,您可以預先填寫帖子的文本和最多10個預期的收件人。用戶可以根據需要進行更改,然後執行實際共享。您可以通過https://developers.google.com/+/web/share/interactive或通過觀看Google+開發人員現場節目http://www.youtube.com/watch?v=U4Iw28jWtAY瞭解更多信息。
+0

thnx joanna .... – dinesh 2013-04-10 06:42:42

0

如果目前您可以創建新的帖子和評論,如果它是相同的域名。閱讀更多here