2010-06-15 107 views
8

如何創建一個鏈接,如果他們已經登錄,會自動讓某個用戶關注某個Twitter用戶,或者如果他們不是,則會將其發送給Twitter以便首先登錄?我已經找到了大約一個月或兩個月前如何做到這一點,但無法再找到它。我認爲這是一個基本的東西,像鏈接或表單發佈到twitter.com/[user_user/follow。Twitter關注鏈接

我已經看過API,但我需要用戶在我的網站上進行身份驗證,我不想處理這個問題。我只想讓他們直接在Twitter上進行身份驗證,而不用擔心。我找到的方式很好,很簡單,我只是想再次找到它。

+3

去檢查你以前的問題的一些正確的答案,然後我們說:P – meo 2010-06-15 19:49:16

回答

0

how to use twitter api in my android application to implement follow button only

的Android

http://code.google.com/p/android-hackathon-in-fukuoka/source/browse/trunk/sodefuri/src/jp/jagfukuoka/sodefuri/TimeLineActivity.java?spec=svn167&r=167

代碼剪斷:(I已經轉換。中國字符串轉換成標準的英語)

public class TimeLineActivity extends ListActivity { 
     private TwitterPreferenceManager tpm = new TwitterPreferenceManager(this); 

     private static final int FOLLOW = 1; 
     private static final CharSequence FOLLOW_LABEL = "Follow"; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
       super.onCreate(savedInstanceState); 

       // timeline Obtaining process 
       String screenName = getIntent().getStringExtra("screen_name"); 
       List<String> list = this.getTimeLine(screenName); 

       setListAdapter(new ArrayAdapter<String>(this, R.layout.timeline_item,list)); 
     } 

     @Override 
     public boolean onCreateOptionsMenu(Menu menu) { 
       menu.add(0, FOLLOW, 0, FOLLOW_LABEL); 
       return super.onCreateOptionsMenu(menu); 
     } 

     @Override 
     public boolean onOptionsItemSelected(MenuItem item) { 
       switch (item.getItemId()) { 
       case FOLLOW: 
         ConfigurationBuilder builder = new ConfigurationBuilder(); 
         Configuration conf = builder.setOAuthAccessToken(tpm.getAccessToken()) 
         .setOAuthAccessTokenSecret(tpm.getAccessTokenSercret()) 
         .setOAuthConsumerKey(TwitterPreferenceManager.CONSUMER_KEY) 
         .setOAuthConsumerSecret(TwitterPreferenceManager.CONSUMER_SERCRET) 
         .setDebugEnabled(true) 
         .build(); 
         Twitter twitter = new TwitterFactory(conf).getInstance(); 
         try { 
           String screen_name = getIntent().getStringExtra("screen_name"); 
           twitter.createFriendship(screen_name); 
           Toast.makeText(getApplicationContext(), "Was to follow.", Toast.LENGTH_LONG).show(); 
         } catch (TwitterException e) { 
           Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); 
           e.printStackTrace(); 
         } 
         break; 

       default: 
         break; 
       } 
       return super.onOptionsItemSelected(item); 
     } 

     /** 
     * Get the time line for the specified user 
     * 
     * @param screenName 
     * @return 
     */ 
     private List<String> getTimeLine(String screenName) { 
       List<String> result = new ArrayList<String>(); 

       Twitter twitter = new TwitterFactory().getInstance(); 
       ResponseList<Status> userTimeline; 
       try { 
         userTimeline = twitter.getUserTimeline(screenName); 
         for (Status status : userTimeline) { 
           result.add(status.getText()); 
         } 
       } catch (TwitterException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
       } 
       return result; 
     } 
} 

iPhone

http://www.chrismaddern.com/twitter-follow-button-for-ios-iphone-code/

這裏是這樣,如何待辦事項

FollowMeButton可以在Interface Builder通過添加一個UIButton並改變其類FollowMeButton創建或者在使用自定義初始化程序的代碼中:

[self.view addSubview:[[FollowMeButton alloc] initWithTwitterAccount:@"chrismaddern" atOrigin:CGPointMake(205, 248) isSmallButton:YES]]; 

通過在初始化程序中設置isSmallButton或稍後更改對象的isSmall屬性,可以控制兩種大小模式。