1

我正在开发一个使用 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”,而不是整个用户信息集。

提前感谢您的帮助!

4

1 回答 1

0

您看到的是整个 UserFeedData 对象的字符串表示形式,而不仅仅是 ID。而不是System.out.println(a.get(i));用来System.out.println(a.get(i).getId());拉取用户的ID。

于 2015-05-08T13:41:36.980 回答