用布在微博无法获得关注者名单 [英] Can't get List of followers in Twitter using Fabric

查看:190
本文介绍了用布在微博无法获得关注者名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 rel=\"nofollow\">面料SDK。在此,我能够做出登录请求,因为它的文档中被描述。现在我wan't获得追随者列表登录的用户,并呈现在 RecycleView 与跟随者的姓名和个人资料图片。我试图像不同的解决方案:

I am using Fabric sdk for Twitter. In this I am able to make login request as it's described in its document. Now I wan't to get list of follower of logged in user and show in RecycleView with follower name and profile image. I have tried various solutions like:

private void getFollowersdReq(long userID) {
        showProgressDialog();


        JsonObjectRequest getRegisterReq = new JsonObjectRequest(Request.Method.GET,
                "https://api.twitter.com/1.1/followers/list.json?cursor=-1&&skip_status=true&include_user_entities=false&user_id=" + userID, null,
                new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        LogUtils.LOGD("Server Response", response.toString());
                        hideProgressDialog();
                    }
                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {
                VolleyLog.d("server Error",
                        "Error: " + error.getMessage());
                Toast.makeText(getActivity(),
                        "Error:" + error.getMessage(), Toast.LENGTH_LONG).show();
                hideProgressDialog();
            }
        }) {

            /**
             * Passing some request headers
             * */
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json");
                headers.put("Accept", "application/json");
                return headers;
            }

        };

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(getRegisterReq, new SignpostUrlStack(twitterToken, secret));

        // Cancelling request
        // ApplicationController.getInstance().getRequestQueue().cancelAll(tag_json_obj);
    }

在上面code我打电话 Twitter的API 以让追随者的列表,但在这我得到错误信息

In above code I am calling Twitter API to get list of followers but in this I am getting error message

{
    "errors": [
        {
            "code": 215,
            "message": "Bad Authentication data."
        }
    ]
}

我也试过

class MyTwitterApiClient extends TwitterApiClient {
        public MyTwitterApiClient(TwitterSession session) {
            super(session);
        }

        public CustomService getCustomService() {
            return getService(CustomService.class);
        }

        public UsersService getUsersService() {
            return getService(UsersService.class);
        }
    }

    interface CustomService {
        @GET("/1.1/followers/list.json")
        void show(@Query("user_id") Long userId,
                  @Query("screen_name") String var,
                  @Query("skip_status") Boolean var1,
                  @Query("include_user_entities") Boolean var2,
                  @Query("count") Integer var3, Callback<User> cb);
    }

    interface UsersService {
        @GET("/1.1/users/show.json")
        void show(@Query("user_id") Long userId,
                  @Query("screen_name") String screenName,
                  @Query("include_entities") Boolean includeEntities,
                  Callback<User> cb);
    }

调用这个类,如:

Called this class like:

new MyTwitterApiClient(session).getCustomService().show(userID, null, true, true, 100, new Callback<User>() {
            @Override
            public void success(Result<User> result) {
                LogUtils.LOGI("Get success",result.toString());
            }

            @Override
            public void failure(TwitterException e) {
                hideProgressDialog();
            }
        });

通过这种方法也是我不能够获得所需的输出。

By this method also I am not able to get desired output.

推荐答案

第二个方法(使用 TwitterApiClient )是除了响应数据模型几乎是正确的。 https://dev.twitter.com/rest/reference/get/followers/列表的响应的结构。您需要按照这个结构建立一个数据模型。
这里是修复:

The second method (using TwitterApiClient) is almost correct except for the response data model. Refere https://dev.twitter.com/rest/reference/get/followers/list for the structure of the response. You need to build a data model according to this structure. Here is the fix :

//data model
public class Followers {
        @SerializedName("users")
        public final List<User> users;

        public Followers(List<User> users) {
            this.users = users;
        }
    }

class MyTwitterApiClient extends TwitterApiClient {
    public MyTwitterApiClient(TwitterSession session) {
        super(session);
    }

    public CustomService getCustomService() {
        return getService(CustomService.class);
    }

}

interface CustomService {@GET("/1.1/followers/list.json")
    void show(@Query("user_id") Long userId, @Query("screen_name") String
    var, @Query("skip_status") Boolean var1, @Query("include_user_entities") Boolean var2, @Query("count") Integer var3, Callback < Followers > cb);
}



new MyTwitterApiClient(session).getCustomService().show(userID, null, true, true, 100, new Callback < Followers > () {@Override
    public void success(Result < Followers > result) {
        Log.i("Get success", "" + result.data.users.size());
    }

    @Override
    public void failure(TwitterException e) {

    }
 });

以上code为我工作。希望它能帮助!

The above code is working for me. Hope it helps!

这篇关于用布在微博无法获得关注者名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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