2012-08-30 57 views
0

我試圖在我的twitter牆上發佈鏈接,就像更新狀態一樣,或者在牆上張貼推文。在Twitter牆上張貼鏈接?

我目前使用twitter4j-core-2.1.11.jar庫在Twitter上發佈推文,但我也想發佈推文鏈接。

我該怎麼做,請幫助!

+0

你有什麼迄今所做? – iTurki

回答

6

這可能對你有幫助!

public class ShareButtonActivity extends Activity { 

    // SocialAuth Component 
    SocialAuthAdapter adapter; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // Welcome Message 
     TextView textview = (TextView)findViewById(R.id.text); 
     textview.setText("Title"); 

     //Create Your Own Share Button 
     Button share = (Button)findViewById(R.id.sharebutton); 
     share.setText("Share"); 
     share.setTextColor(Color.WHITE); 
     share.setBackgroundResource(R.drawable.button_gradient); 

     // Add it to Library 
     adapter = new SocialAuthAdapter(new ResponseListener()); 

     // Add providers 

     adapter.addProvider(Provider.TWITTER, R.drawable.twitter); 

     //before that import library which is given by socialauth in link given below 
     adapter.enable(share); 

    } 


    /** 
    * Listens Response from Library 
    * 
    */ 

    private final class ResponseListener implements DialogListener 
    { 
     public void onComplete(Bundle values) { 

      // Variable to receive message status 

      Log.d("ShareButton" , "Authentication Successful"); 

      // Get name of provider after authentication 
      String providerName = values.getString(SocialAuthAdapter.PROVIDER); 
      Log.d("ShareButton", "Provider Name = " + providerName); 

      adapter.updateStatus("your message|link" + System.currentTimeMillis()); 
      Toast.makeText(ShareButtonActivity.this, "Message posted on " + providerName, Toast.LENGTH_SHORT).show();  

     } 

     public void onError(SocialAuthError error) { 
      Log.d("ShareButton" , "Authentication Error"); 
     } 

     public void onCancel() { 
      Log.d("ShareButton" , "Authentication Cancelled"); 
     } 

    } 

} 

click here

+0

雖然這可能在理論上回答這個問題,但[這將是更可取的](http://meta.stackexchange.com/q/8259)在這裏包括答案的基本部分,並提供供參考的鏈接。 – RivieraKid

+1

也可以通過添加 adapter.addProvider()來添加Facebook,myspace等; 如有必要 –

+0

這顯示錯誤'SocialAuthAdapter無法解析爲類型' – Pari