繁体   English   中英

Android Facebook邀请好友请求不适用于limit参数

[英]Android facebook invitable friends request doesn't work with limit parameter

我想获得邀请的朋友的完整列表,我正在使用此代码

GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends?limit=5000",null, HttpMethod.GET, new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse graphResponse) {
                    try {
                        JSONObject graphObject = graphResponse.getJSONObject();
                        JSONArray dataArray = graphObject.getJSONArray("data");
                        for (int i = 0; i < dataArray.length(); i++) {

                            try {

                                // here all that you want
                                JSONObject object = dataArray.getJSONObject(i);

                                // get facebook user id,name and picture
                                String str_id = object.getString("id");

                                String str_name = object.getString("name");

                                JSONObject picture_obj = object.getJSONObject("picture");

                                JSONObject data_obj = picture_obj.getJSONObject("data");

                                String str_url = data_obj.getString("url");

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

                        }
                    } catch (Exception e) {
                        System.out.println("Exception=" + e);
                        e.printStackTrace();
                    }
                }
            });
            request2.executeAsync();

当我运行它时,它给我一个OAuthException(必须使用活动访问令牌来查询有关当前用户的信息)。 有趣的是,当我删除limit参数并仅发送/ me / invitable_friends时,该调用有效,但给我默认的25个带有分页数据对象的结果。 我从一开始就需要数据对象中的所有结果,因此我需要使用limit参数。 有什么想法我可以使它工作吗?

您应该做的是将参数作为Bundle传递给GraphRequest对象。

像这样:

Bundle args = new Bundle();
args.putInt("limit", 150);

因此,稍后您可以将其传递给您的GraphRequest:

Bundle args = new Bundle();
args.putInt("limit", 150);
GraphRequest request2 = new GraphRequest(tokenObj,"/me/invitable_friends", args, HttpMethod.GET, new GraphRequest.Callback() {
            @Override
            public void onCompleted(GraphResponse graphResponse) {
                try {
                    JSONObject graphObject = graphResponse.getJSONObject();
                    JSONArray dataArray = graphObject.getJSONArray("data");
                    for (int i = 0; i < dataArray.length(); i++) {

                        try {

                            // here all that you want
                            JSONObject object = dataArray.getJSONObject(i);

                            // get facebook user id,name and picture
                            String str_id = object.getString("id");

                            String str_name = object.getString("name");

                            JSONObject picture_obj = object.getJSONObject("picture");

                            JSONObject data_obj = picture_obj.getJSONObject("data");

                            String str_url = data_obj.getString("url");

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

                    }
                } catch (Exception e) {
                    System.out.println("Exception=" + e);
                    e.printStackTrace();
                }
            }
        });
        request2.executeAsync();

没有它,您将只能获得25个朋友(使用分页系统,您仍然可以得到更多)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM