Get Second Level features of social network through Twitter Api

不问归期 提交于 2019-12-25 12:13:08

问题


I am trying to get second level features of my twitter personal network using twitter4j library. When I refer to second level features I mean the followers of my followers, the followees of my followees etc.

I've started with my followees first using the following code:

try{
    twitter = tf.getInstance();
    long cursor = -1;
    IDs ids = twitter.getFriendsIDs(cursor);

    long[] id = ids.getIDs();
    ResponseList<User> users = twitter.lookupUsers(id); 
}
catch (Exception e) {
    logger.warn("Error {}",e.getLocalizedMessage());
    e.printStackTrace();
}

Using the above I am getting my friends. But I am struggling to get the friends of friends. I've read that giving my twitter keys I am authorized to get second level features but not further that that.

Any help is appreciated.


回答1:


Let me write a sample below: First block is for finding followers of a particular tweet user.

    long lCursor = -1, nextCursor = -1;
    IDs friendsIDs = null;

    followerIDListOfOriginalTweeter = new ArrayList<>();

            do
            {
                lCursor = nextCursor;
                try
                {
                    friendsIDs = twitterObj.getFollowersIDs(originalTweetUserId, lCursor);
                }
                catch (Exception ex)
                {
                    logWriter.Write(ex);
                }

                nextCursor = friendsIDs.getNextCursor();

             } while (nextCursor != 0);


The second block is for finding followers of followers:

    IDs friendsIDs = null;
    long lCursor = -1, nextCursor = -1;

    try
        {
            do
              {
                    followers = new Followers();

                    nextCursor = -1;

                    do
                    {
                        lCursor = nextCursor;

                        try
                        {
                friendsIDs = twitterObj.getFollowersIDs(followers.currentUserId, lCursor);
                        }
                        catch (Exception ex)
                        {
                          logWriter.Write(ex);

                        }

                        for (long followerId : friendsIDs.getIDs())
                        {                            
                           system.out.println(followerId);
                        }

                        nextCursor = friendsIDs.getNextCursor();

                    } while (nextCursor != 0);

            } while (rsForSelectNotCompletedRetweetsQuery.next());


来源:https://stackoverflow.com/questions/20633781/get-second-level-features-of-social-network-through-twitter-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!