簡體   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