【问题标题】:How do turn twitter IDs to Username in twitter4j? Or can I use id to get a user bio?如何在 twitter4j 中将 twitter ID 转换为用户名?或者我可以使用 id 来获取用户简介吗?
【发布时间】:2021-11-18 11:59:45
【问题描述】:

所以我从

那里得到了一堆ID
do {
    if (0 < SklsIds.length) {
        ids = twitter.getFriendsIDs(identlong, cursor);
    } else {
        ids = twitter.getFriendsIDs(cursor);
    }
    for (long id : ids.getIDs()) {
        followers.add(id);
    }
} while ((cursor = ids.getNextCursor()) != 0);

然后我想使用这些 id 获取用户简介:

for (Long ideez : followers) {
    System.out.println(twitter.showUser(ideez.toString()));
    String bio = ideez.toString().getDescription().toLowerCase();
}

我有这个 rn,但我认为您无法仅使用 id 或其他任何内容来获取用户的简历。请帮忙

【问题讨论】:

    标签: java twitter twitter4j


    【解决方案1】:

    我们可以这样做来检索我们的 Twitter 用户朋友的姓名和简介:

    try {
        Twitter twitter = new TwitterFactory(cb.build()).getInstance();
        long cursor = -1;
        IDs ids;
        System.out.println("Listing followers's ids.");
        do {
            ids = twitter.getFriendsIDs(cursor);
            // Retrieve the follower IDs into an array
            long[] userIds = ids.getIDs();
            // Iterate through the array in batches of 100. We need batches of 100 because lookupUser method accept at most 100 ids
            for (int i = 0; i < userIds.length; i += 100) {
                ResponseList<User> users = twitter.lookupUsers(Arrays.copyOfRange(ids.getIDs(), i, Math.min(i + 100, userIds.length)));
                // Iterate through the users and retrieve information about them
                for (User user : users) {
                    // Do something with the user name
                    System.out.println(user.getName());
    
                    // Do something with the bio description
                    System.out.println(user.getDescription());
                }
            }
        } while ((cursor = ids.getNextCursor()) != 0);
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get followers' ids: " + te.getMessage());
        System.exit(-1);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多