使用 Twitter4J 的好友的好友列表

发布于 2024-12-27 13:01:20 字数 338 浏览 1 评论 0原文

How can I obtain the friends list of a friend or follower using Twitter4J?

Using getFriendsId(), I'm only able to retrieve the friend's/follower's list of that current user which is authenticated. What I want is to obtain the list of friends of a follower or friend of the authenticated user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

哭泣的笑容 2025-01-03 13:01:20

这将显示您朋友的关注者的姓名。

      User u1 = null ;
      long cursor = -1;
      IDs ids;
      System.out.println("Listing followers's ids.");
      do {
              ids = twitter.getFollowersIDs("username", cursor);
          for (long id : ids.getIDs()) {
              System.out.println(id);
              User user = twitter.showUser(id);
              System.out.println(user.getName());
          }
      } while ((cursor = ids.getNextCursor()) != 0);

This will show the name of your friend's followers.

      User u1 = null ;
      long cursor = -1;
      IDs ids;
      System.out.println("Listing followers's ids.");
      do {
              ids = twitter.getFollowersIDs("username", cursor);
          for (long id : ids.getIDs()) {
              System.out.println(id);
              User user = twitter.showUser(id);
              System.out.println(user.getName());
          }
      } while ((cursor = ids.getNextCursor()) != 0);
为你鎻心 2025-01-03 13:01:20

你只需要这样做:

Twitter twitter = mTwitterApp.getTwitterInstance();
long cursor = -1;
List<User> users=twitter.getFriendsList(mTwitterApp.getUserID(), cursor);

这里的用户是你的朋友的列表用户(你正在关注他们)。
mTwitterApp.getUserID() 是您的登录用户,它是一个长值。

You only need to do this:

Twitter twitter = mTwitterApp.getTwitterInstance();
long cursor = -1;
List<User> users=twitter.getFriendsList(mTwitterApp.getUserID(), cursor);

Here users is a list users who are your friends(you are following them).
mTwitterApp.getUserID() is your login useris which is a long value.

暖风昔人 2025-01-03 13:01:20
long lCursor = -1;
IDs friendsIDs = twitter.getFriendsIDs(userID, lCursor);
System.out.println(twitter.showUser(userID).getName());
System.out.println("==========================");
do
{
  for (long i : friendsIDs.getIDs())
   {
       System.out.println("follower ID #" + i);
       System.out.println(twitter.showUser(i).getName());
   }
}while(friendsIDs.hasNext());
long lCursor = -1;
IDs friendsIDs = twitter.getFriendsIDs(userID, lCursor);
System.out.println(twitter.showUser(userID).getName());
System.out.println("==========================");
do
{
  for (long i : friendsIDs.getIDs())
   {
       System.out.println("follower ID #" + i);
       System.out.println(twitter.showUser(i).getName());
   }
}while(friendsIDs.hasNext());
南城旧梦 2025-01-03 13:01:20

此代码有效!(不超过速率限制)。参考了 twitter4j 文档 以及 StackOverflow 上的其他答案。

    try {
            // get friends
            long cursor = -1;
            PagableResponseList<User> pagableFollowings;
            do {
                pagableFollowings = twitter.getFriendsList(twitter.getId(), cursor);
                for (User user : pagableFollowings) {
                    listFriends.add(user); // ArrayList<User>
                }
            } while ((cursor = pagableFollowings.getNextCursor()) != 0);

            // get followers
            cursor = -1;
            PagableResponseList<User> pagableFollowers;
            do {
                pagableFollowers = twitter.getFollowersList(twitter.getId(), cursor);
                for (User user : pagableFollowers) {
                    listFollowers.add(user); // ArrayList<User>
                }
            } while ((cursor = pagableFollowers.getNextCursor()) != 0);

        } catch (TwitterException e) {
            printError(e);
        }

This code works! (without exceeding rate limits). Referred twitter4j documentation and other answers on StackOverflow.

    try {
            // get friends
            long cursor = -1;
            PagableResponseList<User> pagableFollowings;
            do {
                pagableFollowings = twitter.getFriendsList(twitter.getId(), cursor);
                for (User user : pagableFollowings) {
                    listFriends.add(user); // ArrayList<User>
                }
            } while ((cursor = pagableFollowings.getNextCursor()) != 0);

            // get followers
            cursor = -1;
            PagableResponseList<User> pagableFollowers;
            do {
                pagableFollowers = twitter.getFollowersList(twitter.getId(), cursor);
                for (User user : pagableFollowers) {
                    listFollowers.add(user); // ArrayList<User>
                }
            } while ((cursor = pagableFollowers.getNextCursor()) != 0);

        } catch (TwitterException e) {
            printError(e);
        }
回首观望 2025-01-03 13:01:20

您可以使用

twitter.getFollowersIDs("username", cursor);

http://twitter4j.org /javadoc/twitter4j/api/FriendsFollowersResources.html#getFollowersIDs-java.lang.String-long-
它仅返回 5000 个用户,而不是所有用户。而且 15 分钟内限制 15 次。(https://dev.twitter. com/rest/reference/get/friends/ids

此外,您还可以使用,

twitter.getFollowersList("username", cursor);

http://twitter4j.org/javadoc/twitter4j/ api/FriendsFollowersResources.html#getFollowersList-java.lang.String-long- 也限制为 20 个用户。此外,用户身份验证在 15 分钟内限制为 15 次,应用程序身份验证在 15 分钟内限制为 30 次 (https://dev.twitter.com/rest/reference/get/friends/list

要无限制访问,您可以查看https://gnip.com/ 或 twitter 的白名单用户访问。

You can use

twitter.getFollowersIDs("username", cursor);

http://twitter4j.org/javadoc/twitter4j/api/FriendsFollowersResources.html#getFollowersIDs-java.lang.String-long-
which returns only 5000 user not all users. Also it is limited 15 times in 15 minutes.(https://dev.twitter.com/rest/reference/get/friends/ids)

Also, you can use,

twitter.getFollowersList("username", cursor);

http://twitter4j.org/javadoc/twitter4j/api/FriendsFollowersResources.html#getFollowersList-java.lang.String-long- which is also limited with 20 user. Also it is limited 15 times in 15 minutes for user auth, 30 times in 15 minutes for app auth (https://dev.twitter.com/rest/reference/get/friends/list)

For unlimited access, you can look at https://gnip.com/ or whitelisted user access of twitter.

很糊涂小朋友 2025-01-03 13:01:20
         PagableResponseList<User> friendlist= twitter.getFriendsList(user.getScreenName(), -1);

         int sizeoffreindlist= friendlist.size();

         for(int i=0;i<sizeoffreindlist;i++)
         {
             System.out.println(friendlist.get(i));
         }

它将为您提供 20 个好友的列表,因为默认限制为 20 个

         PagableResponseList<User> friendlist= twitter.getFriendsList(user.getScreenName(), -1);

         int sizeoffreindlist= friendlist.size();

         for(int i=0;i<sizeoffreindlist;i++)
         {
             System.out.println(friendlist.get(i));
         }

It will provide you a list of 20 friends as the default limit is 20

心凉 2025-01-03 13:01:20

获取好友列表之类的东西怎么样? https://dev.twitter.com/docs/api/1.1/get /friends/list

根据文档:

返回每个用户的用户对象的游标集合
指定的用户正在关注(也称为他们的“朋友”)。

twitter4j.api 中有一个接口,但我不知道如何使用它:

PagableResponseList<User> getFriendsList(String screenName, long cursor) throws TwitterException;

What about something like get Friends List? https://dev.twitter.com/docs/api/1.1/get/friends/list

According to the docs:

Returns a cursored collection of user objects for every user the
specified user is following (otherwise known as their "friends").

There is an interface for this in twitter4j.api, but I can't figure out how to use it:

PagableResponseList<User> getFriendsList(String screenName, long cursor) throws TwitterException;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文