通过 Twitter Api 获取社交网络的二级功能 [英] Get Second Level features of social network through Twitter Api

查看:33
本文介绍了通过 Twitter Api 获取社交网络的二级功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 twitter4j 库获取我的 twitter 个人网络的二级功能.当我提到二级特征时,我指的是我的关注者的关注者、我的关注者的关注者等.

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();
}

使用上面的我得到了我的朋友.但我正在努力获得朋友的朋友.我读过给我的 twitter 密钥我被授权获得二级功能,但不能进一步.

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.

感谢任何帮助.

推荐答案

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());

这篇关于通过 Twitter Api 获取社交网络的二级功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆