如何从Facebook登录我的应用程序获取朋友列表

时间:2015-08-18 06:01:31

标签: android facebook-graph-api facebook-android-sdk

目前我正在使用facebook sdk 4.4.0,现在我想用他们使用我的应用程序的emailid获取朋友,或者他们至少登录了我的应用程序。

我推荐这个 - https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends

我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以通过BatchRequest

获取它们
GraphRequestBatch batch = new GraphRequestBatch(GraphRequest.newMyFriendsRequest(
                    accesstoken,
                    new GraphRequest.GraphJSONArrayCallback() {
                        @Override
                        public void onCompleted(JSONArray jsonArray, GraphResponse response) {
                            System.out.println("jsonArray: "+jsonArray);
                            System.out.println("GraphResponse: "+response);
                            try {
                                ArrayList<Friend_List_Load> item_details = new ArrayList<Friend_List_Load>();
                                for(int i=0; i<jsonArray.length();i++){
                                    JSONObject c=jsonArray.getJSONObject(i);
                                    System.out.println("id: "+c.getString(PROFILE_ID));
                                    System.out.println("name: "+c.getString(NAME));
                                    FriendListAdapter frndadapter=new FriendListAdapter(FriendList.this,item_details);
                                    item_details.add(new Friend_List_Load(c.getString(NAME),c.getString(PROFILE_ID)));
                                    lv_friends.setAdapter(frndadapter);
                                }                   
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }

                        }
                    }),
                    GraphRequest.newMeRequest(accesstoken, new GraphRequest.GraphJSONObjectCallback() {

                        @Override
                        public void onCompleted(JSONObject object, GraphResponse response) {
                            System.out.println("meJSONObject: "+object);
                            System.out.println("meGraphResponse: "+response);

                        }
                    })
    );
    batch.addCallback(new GraphRequestBatch.Callback() {
        @Override
        public void onBatchCompleted(GraphRequestBatch graphRequests) {
            //Log.i(TAG, "onCompleted: graphRequests "+ graphRequests);
        }
    });
    batch.executeAsync();

onCompleted中,您可以获得回复。