我正在使用一个使用jInstagram api的java应用程序。我可以使用我的应用程序成功登录,但是当我想获得跟随某个用户的用户列表时,我只能收集50个用户ID。
我用来吸引50位关注用户的用户的代码是:
String userId = instagram.getCurrentUserInfo().getData().getId();
UserFeed feed = instagram.getUserFollowedByList(userId);
List<UserFeedData> users = feed.getUserList();
//iterate through the list and print each value. The print value is simply a user id.
然后我可以遍历列表并打印出50个用户ID。这很好,但我需要获得更多用户ID。
从我的研究中,为了获得超过50个用户ID,我必须使用Pagination类。这是我放在一起的东西。
String userId = instagram.getCurrentUserInfo().getData().getId();
UserFeed feed = instagram.getUserFollowList(userId);
UserFeed recentData = instagram.getUserFollowedByListNextPage(feed.getPagination());
int counter = 0;
while(recentData.getPagination() != null && counter < 10){
List<UserFeedData> a = recentData.getUserList();
for(int i = 0; i < a.size(); i++){
System.out.println(a.get(i));
}
counter++;
}
此代码有效,但它为每个用户提供了这样的输出。
UserFeedData [id=316470004, profilePictureUrl=https://instagramimages-a.akamaihd.net/profiles/profile_316470004_75sq_1386826158.jpg, userName=thebeautifulwarrior, fullName=Dee Shower, website=http://www.totallifechanges.com/dns2015, bio=2015 the year to Reinvent & Restore! Lose 10 pounds in 10 days!!! Ask me how. Invest in yourself. E-mail: totallifechange2015@gmail.com]
对于我的程序,我只想要id部分。我知道我可以解析文本并创建子字符串,但我希望更有效地执行此操作并从api调用中检索数据。在第一段代码中,它给出了我需要它的输出。例如,代码的输出是“316470004”而不是整个用户信息集。
提前感谢您的帮助!
答案 0 :(得分:0)
您所看到的是整个UserFeedData对象的字符串表示形式,而不仅仅是ID。而不是System.out.println(a.get(i));
使用System.out.println(a.get(i).getId());
来提取用户的ID。