我如何创建一个链接,如果用户已登录,则会自动让用户关注某个Twitter用户,或者如果他们不登录则将其发送到Twitter首先登录?我在一两个月前找到了如何做到这一点,但再也找不到了。我认为这是基本的东西,如链接或表格帖子,如twitter.com/[user]/follow。
我查看了API,但我需要用户在我的网站上验证自己,我不想处理它。我只是希望他们直接在Twitter上进行身份验证而不用担心。我找到的方式很简单,我只想再找到它。
答案 0 :(得分:17)
使用Twitter的新web intents。
答案 1 :(得分:0)
how to use twitter api in my android application to implement follow button only
<强>的Android 强>
Code Snip:(我已将中文字符串转换为标准英语)
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/
这是方式,怎么待的
可以在Interface Builder中创建 FollowMeButton ,方法是添加UIButton并将其类更改为FollowMeButton,或使用自定义初始化程序在代码中创建
[self.view addSubview:[[FollowMeButton alloc] initWithTwitterAccount:@"chrismaddern" atOrigin:CGPointMake(205, 248) isSmallButton:YES]];
通过在初始化程序中设置isSmallButton或稍后更改对象的isSmall属性来控制两种大小模式。