2013-08-16 97 views
0

我正在創建一個應用程序分享到Facebook的東西。在這裏,當我點擊一個按鈕時,Feed對話框將用於共享,還有一個用於添加消息的文本框,我的需要是我需要將數據從我的代碼發送到文本框。我怎麼發送它?如何發送消息到飼料對話框使用Facebook的SDK在Android

這是我的代碼來顯示Feed對話框。

private void showFeedDialog() { 
     Bundle postParams = new Bundle(); 
     postParams.putString("description","message from me "); 
     postParams.putString("link", "https://www.google.com"); 
     WebDialog feedDialog = new WebDialog.FeedDialogBuilder(this, Session.getActiveSession(),postParams) 
     .setOnCompleteListener(new OnCompleteListener() { 
      @Override 
      public void onComplete(Bundle values, FacebookException error) { 
       if(error==null) 
       { 
        final String postId=values.getString("post_id"); 
        if(postId!=null) 
         Toast.makeText(getApplicationContext(), "Posted Successfully", Toast.LENGTH_SHORT).show(); 
        else 
         Toast.makeText(getApplicationContext(), "Post canceled", Toast.LENGTH_SHORT).show(); 
       } 
       else 
        if(error instanceof FacebookOperationCanceledException) 
         Toast.makeText(getApplicationContext(), "Publish canceled",Toast.LENGTH_SHORT).show(); 
        else 
         Toast.makeText(getApplicationContext(), "connection error", Toast.LENGTH_SHORT).show(); 
      } 
     }).build(); 
     feedDialog.show(); 

    } 

回答

2

您不能指定一個用戶信息,以供對話框。 「名稱」,「標題」和「描述」字段僅適用於共享的「鏈接」。

這是設計。

+0

有什麼方法可以更新用戶消息在Feed對話框中? –

+0

不,這將是「預先填寫信息」,這是違反FB的平臺政策。 –

+0

哪個參數適用於Facebook朋友的牆上文本字段上傳遞字符串的應用程序? – Jigsh

0

發佈爲使用新的Facebook SDK 3.0 Feed中的代碼如下:

// Method for publishing a feed to Facebook 
private void publishStory() { 
    Session session = Session.getActiveSession(); 

    Bundle postParams = new Bundle(); 
    postParams.putString("name", "Facebook SDK 3.0 Test By Arshad"); 
    postParams.putString("caption", "Build great social apps and get more installs."); 
    postParams.putString("description", 
        "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); 
    postParams.putString("link", "https://developers.facebook.com/android"); 
    postParams.putString("picture", 
        "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); 

    Request.Callback callback = new Request.Callback() { 
     public void onCompleted(Response response) { 
      Log.i(TAG, "onCompleted FacebookRequest Done"); 
      JSONObject graphResponse = response.getGraphObject() 
        .getInnerJSONObject(); 
      try { 
       graphResponse.getString("id"); 
      } catch (JSONException e) { 
       Log.i(TAG, "JSON error " + e.getMessage()); 
      } 
      FacebookRequestError error = response.getError(); 
      if (error != null) { 
       Log.i(TAG, "FacebookRequestError" + error.getErrorMessage()); 
       Toast.makeText(getActivity().getApplicationContext(), 
         error.getErrorMessage(), Toast.LENGTH_SHORT).show(); 
      } else { 
       Log.i(TAG, "FacebookRequest Done"); 
       Toast.makeText(getActivity().getApplicationContext(), 
         "Story Published to Your Wall", Toast.LENGTH_LONG).show(); 
      } 
     } 
    }; 

    Request request = new Request(session, "me/feed", postParams, 
      HttpMethod.POST, callback); 

    RequestAsyncTask task = new RequestAsyncTask(request); 
    task.execute(); 
} 
+0

信息您可以在任何三個字段通過您的信息:姓名,標題或說明。 – Arshu

+0

ya我按照你說的那樣傳遞它..但它沒有出現在提要對話框中的文本框中..它出現在文本框 – ranjith

+0

的下面嘗試使用上面粘貼的方法,然後回覆 – Arshu

0

要發佈從活動中使用該

Bundle postParams = new Bundle(); 
    postParams.putString("message", "your message"); 
    postParams.putString("name", "Facebook SDK 3.0 Test By Arshad"); 
    postParams.putString("caption", "Build great social apps and get more installs."); 
    postParams.putString("description", 
        "The Facebook SDK for Android makes it easier and faster to develop Facebook integrated Android apps."); 
    postParams.putString("link", "https://developers.facebook.com/android"); 
    postParams.putString("picture", 
        "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png"); 
相關問題