【问题标题】:jinstagram api - get complete user listinstagram api - 获取完整的用户列表
【发布时间】:2015-01-31 06:20:20
【问题描述】:

我正在开发一个使用 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 调用中检索数据。在代码的第一个 sn-p 中,它给出了我需要的输出。例如,代码的输出是“316470004”,而不是整个用户信息集。

提前感谢您的帮助!

【问题讨论】:

    标签: java twitter instagram instagram-api


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-27
      • 2012-12-15
      • 2018-03-13
      • 2015-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多