2012-01-17 55 views
1

this postthis tutorial的幫助下,我設法將我的Android應用上的Facebook與最新的FacebookSDK集成在一起。我想發佈一些內容,這樣使用的教程及其工作完全正常......我唯一的問題是,我無法看到發佈對話框(如該教程中提到的),在那裏,我希望它顯示爲我想用戶修改消息的內容......我該怎麼做這個如何顯示發佈對話框,當使用Facebook與Android的Android手機上使用最新的FacebookSDK集成

這裏是我使用發佈後的代碼的快照。

public void postToWall(String message){ 
    Bundle parameters = new Bundle(); 
      parameters.putString("message", message); 
      parameters.putString("description", "topic share"); 
      try { 
       facebook.request("me"); 

     String response = facebook.request("me/feed", parameters, "POST"); 

     Log.d("Tests", "got response: " + response); 
     if (response == null || response.equals("") || 
       response.equals("false")) { 
      showToast("Blank response."); 
     } 
     else { 
      showToast("Message posted to your facebook wall!"); 
     } 
     finish(); 
    } catch (Exception e) { 
     showToast("Failed to post to wall!"); 
     e.printStackTrace(); 
     finish(); 
    } 
} 

與權限

private static final String[] PERMISSIONS = new String[] {"publish_stream"}; 

我還發現,有一些所謂的facebook.dialog(),但我不知道在哪裏,以及如何使用它...

所以,請讓我知道如何顯示發佈對話框。

謝謝

拉吉

回答

1

您將使用牆壁上沒有發佈對話編碼。

my only issue is that I am not able to see the publish dialog box (as mentioned in the tutorial), where as I want it to be shown as I want user to modify the contents of the message.. 

使用以下代碼片段顯示對話框:

private void post_facebook() { 
    Bundle parameters = new Bundle(); 
    parameters.putString("method", "stream.publish"); 

    JSONObject attachment = new JSONObject(); 

    try { 
     attachment.put("message", "Messages"); 
     attachment.put("name", "Check out"); 
     attachment.put("href", "http://www.google.com"); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    parameters.putString("attachment", attachment.toString()); 

    authenticatedFacebook.dialog(Activity.this, "stream.publish",parameters, new TestUiServerListener()); 
} 

    public class TestUiServerListener implements DialogListener { 
    public void onComplete(Bundle values) { 
     final String postId = values.getString("post_id"); 
     if (postId != null) { 
      new AsyncFacebookRunner(authenticatedFacebook).request(postId,new TestPostRequestListener()); 
     } else { 
      Activity.this.runOnUiThread(new Runnable() { 
       public void run() { 
       } 
      }); 
     } 
    } 

    public void onCancel() { 
    } 

    public void onError(DialogError e) { 
     e.printStackTrace(); 
    } 

    public void onFacebookError(FacebookError e) { 
     e.printStackTrace(); 
    } 
} 

public class TestPostRequestListener implements RequestListener { 
    public void onComplete(final String response, final Object state) { 
     try { 
      JSONObject json = Util.parseJson(response); 
      String postId = json.getString("id"); 
      Activity.this.runOnUiThread(new Runnable() { 
       public void run() { 
       } 
      }); 
     } catch (Throwable e) { 
     } 
    } 

    public void onFacebookError(FacebookError e, final Object state) { 
     e.printStackTrace(); 
    } 

    public void onFileNotFoundException(FileNotFoundException e, 
      final Object state) { 
     e.printStackTrace(); 
    } 

    public void onIOException(IOException e, final Object state) { 
     e.printStackTrace(); 
    } 

    public void onMalformedURLException(MalformedURLException e, 
      final Object state) { 
     e.printStackTrace(); 
    } 
} 

哪裏authenticatedFacebook就是Facebook的對象。

+0

謝謝你快速幫助... – Nik 2012-01-17 11:12:30

+0

嗨Venky,我還需要了解更多有關參數,您使用附件...因爲我需要用它的圖像共享特定網址 – Nik 2012-01-18 12:28:47

相關問題