我正在使用TwitterFactory:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("xxxxxxxxxxxxxx")
.setOAuthConsumerSecret("xxxxxxxxxxxxx")
.setOAuthAccessToken(xxxxxxxxxxxxx )
.setOAuthAccessTokenSecret(xxxxxxxxxxxxx);
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
long cursor = -1;
IDs ids = twitter.getFollowersIDs(cursor);
问题是我不想要ID,但我需要获得粉丝的用户名,我无法弄清楚如何? 你有什么想法我应该得到用户名?
更新代码:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("xxxxxxxxxxxxxx")
.setOAuthConsumerSecret("xxxxxxxxxxxxx")
.setOAuthAccessToken(xxxxxxxxxxxxx )
.setOAuthAccessTokenSecret(xxxxxxxxxxxxx);
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
long cursor = -1;
IDs ids = twitter.getFollowersIDs(cursor);
long[] id = ids.getIDs();
ResponseList<User> users = twitter.lookupUsers(id);
for (User user : users) {
usernames.add(user.getScreenName());
}
}
答案 0 :(得分:0)
由于获取用户名是一个额外的调用,这里是我制作的一个方法,可以批量调用它们。对于我的用法,我将它们映射到静态地图,但你明白了。
public static HashMap<Long,String> usernameMap = new HashMap<Long,String>();
public static void requestBatch(long[] batch,Twitter twitter) throws TwitterException
{
ResponseList<User> responseList = twitter.lookupUsers(batch);
for(User u : responseList){
usernameMap.put(u.getId(), u.getScreenName());
}
}