How to convert friend id's to corresponding name in twitter using twitter4j?

偶尔善良 提交于 2019-12-12 02:07:41

问题


Here I'm able to get all friends ids. But for the same I need to get name of corresponding id. How can I get it? For getting friends ids I'm using Twitter4j lib and my code is:

String friendsIds = twitter.getFriendsIDs(MyId, cursor).toString();

For this output is:

friendsIds:IDsJSONImpl{ids=[43347766, 2369925598, 238933377, 243381784, 946613156, 541261639], previousCursor=0, nextCursor=0}

How can I get names for those ids?


回答1:


You can use lookupUsers(long[]) to bulk retrieve your friends and get access to their screen names, e.g.:

final IDs friendIds = twitter.getFriendsIDs(MyId, cursor);
final ResponseList<User> users = twitter.lookupUsers(friendIds.getIDs());

for (User u : users) {
    System.out.println(u.getScreenName());
}

Note that you can retrieve up to a maximum of 100 users at a time using the lookupUsers API call, so you may have to split the ids up if you have more than 100 friends.



来源:https://stackoverflow.com/questions/24135504/how-to-convert-friend-ids-to-corresponding-name-in-twitter-using-twitter4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!