如何使用twitter4j获取所有Twitter关注者的列表? [英] How to get list of all twitter followers using twitter4j?

查看:290
本文介绍了如何使用twitter4j获取所有Twitter关注者的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想是否有一种方法可以访问所有推特关注者列表.

I have been wondering if there is a way to access all the twitter followers list.

我们尝试通过twitter4j使用对 REST API 的调用:

We have tried using call to the REST API via twitter4j:

  public List<User> getFriendList() {
    List<User> friendList = null;
    try {
        friendList = mTwitter.getFollowersList(mTwitter.getId(), -1);

    } catch (IllegalStateException e) {
        e.printStackTrace();
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    return friendList;
}

但是它仅返回20个关注者的列表.

But it returns only a list of 20 followers.

我尝试使用相同的循环调用,但这会导致限速例外-说我们不允许在短时间内提出太多请求.

I tried using the same call in loop, but it cause a rate limit exception - says we are not allowed to make too many requests in a small interval of time.

我们有办法解决吗?

推荐答案

像这样更改并尝试,这对我有用

Just Change like this and try, this is working for me

    try {
        Log.i("act twitter...........", "ModifiedCustomTabBarActivity.class");
        // final JSONArray twitterFriendsIDsJsonArray = new JSONArray();
        IDs ids = mTwitter.mTwitter.getFriendsIDs(-1);// ids
        // for (long id : ids.getIDs()) {
        do {
            for (long id : ids.getIDs()) {               


                String ID = "followers ID #" + id;
                String[] firstname = ID.split("#");
                String first_Name = firstname[0];
                String Id = firstname[1];

                Log.i("split...........", first_Name + Id);

                String Name = mTwitter.mTwitter.showUser(id).getName();
                String screenname = mTwitter.mTwitter.showUser(id).getScreenName();


  //            Log.i("id.......", "followers ID #" + id);
    //          Log.i("Name..", mTwitter.mTwitter.showUser(id).getName());
    //          Log.i("Screen_Name...", mTwitter.mTwitter.showUser(id).getScreenName());
    //          Log.i("image...", mTwitter.mTwitter.showUser(id).getProfileImageURL());


            }
        } while (ids.hasNext());

    } catch (Exception e) {
        e.printStackTrace();
    }

这篇关于如何使用twitter4j获取所有Twitter关注者的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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