2010-08-13 56 views
6

我使用此代碼在Facebook上發佈,但它不適用於官方Facebook應用程序,因爲它試圖發送鏈接。有沒有辦法解決?Android Facebook意圖

Intent s = new Intent(android.content.Intent.ACTION_SEND); 

s.setType("text/plain"); 
s.putExtra(Intent.EXTRA_SUBJECT, "Quote"); 
s.putExtra(Intent.EXTRA_TEXT, qoute); 

startActivity(Intent.createChooser(s, "Quote")); 
+0

你能更全面地解釋你的意思嗎?您的意思是,當您從共享菜單中選擇它時,Facebook應用程序將打開,但EXTRA_TEXT字段是共享URL而不是共享消息? – matto1990 2010-08-13 22:29:18

+0

興奮。我使用這個意圖通過短信,電子郵件,推特,臉譜等分享文本......問題是,如果我從彈出的選擇中選擇Facebook,「EXTRA_TEXT,qoute」字符串將作爲URL分享給Facebook。這隻會發生在由開發人員「臉譜」的Facebook應用程序。 – zaid 2010-08-15 00:34:02

回答

7

這是官方Facebook應用程序中的一個錯誤。我必須編寫自己的活動才能使用Facebook SDK for Android進行編寫。請參閱下面的代碼示例。

public class FacebookActivity extends Activity implements DialogListener 
{ 

    private Facebook facebookClient; 
    private LinearLayout facebookButton; 
    private final String APP_API_ID = "XXXXXXXX"; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
     super.onCreate(savedInstanceState); 
     facebookClient = new Facebook(); 
     // replace APP_API_ID with your own 
     facebookClient.authorize(this, APP_API_ID, 
      new String[] {"publish_stream", "read_stream", "offline_access"}, this); 


    } 

    @Override 
    public void onComplete(Bundle values) 
    { 

     if (values.isEmpty()) 
     { 
      //"skip" clicked ? 

     } 

     // if facebookClient.authorize(...) was successful, this runs 
     // this also runs after successful post 
     // after posting, "post_id" is added to the values bundle 
     // I use that to differentiate between a call from 
     // faceBook.authorize(...) and a call from a successful post 
     // is there a better way of doing this? 
     if (!values.containsKey("post_id")) 
     { 
      try 
      { 
       Bundle parameters = new Bundle(); 
       parameters.putString("message", "YOUR TEXT TO SHARE GOES HERE");// the message to post to the wall 
       facebookClient.dialog(this, "stream.publish", parameters, this);// "stream.publish" is an API call 


      } 
      catch (Exception e) 
      { 
       // TODO: handle exception 
       System.out.println(e.getMessage()); 
      } 

     } 

    } 

    @Override 
    public void onError(DialogError e) 
    {  
     return; 
    } 

    @Override 
    public void onFacebookError(FacebookError e) 
    { 
     return; 
    } 

    @Override 
    public void onCancel() 
    {  
     return;  
    } 

}