Android me / invitable_friends facebook api只返回名字

时间:2015-03-16 14:58:49

标签: android facebook facebook-graph-api-v2.0

我开发了一个应用程序,

我显示我所有的邀请朋友列表,

使用以下代码

Request invitableFriendsRequest = Request.newGraphPathRequest(session, "me/invitable_friends",
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {

                    FacebookRequestError error = response.getError();
                    if (error != null) {
                        Log.e(CricoApplication.TAG, error.toString());
                        // handleError(error, true);
                    } else if (session == Session.getActiveSession()) {
                        if (response != null) {
                            // Get the result
                            GraphObject graphObject = response.getGraphObject();
                            System.out.println("graph object="+graphObject.toString());
                            JSONArray dataArray = (JSONArray) graphObject.getProperty("data");

                            List<JSONObject> invitableFriends = new ArrayList<JSONObject>();



                            challengeContainer_img_invite_friend.setVisibility(View.VISIBLE);
                                .
                                .
                                . (other code)
                            }

                            application.setInvitableFriends(invitableFriends);
                        }
                    }
                }

            });

但它给出了以下回应:

  {
"picture": {
    "data": {
        "url": "https://fbcdn-profiles-a.akamaiinghd.net/hprofile-ak-xap1/v/t1.0-1/p500x50/10897025_400774666748182_4343469003368936657_n.jpg?oh=c861a98253886fd2bb0a4963ee79400f&oe=55BBE06B&__gda__=1434858589_ba835b66a897aa40cdc90623009b27db",
        "is_silhouette": false
    }
},
"id": "AVle8JLHBBCA848fq-xXVO62ELon1MCPAyMhOubpggokm-  HQ4EYb_ugHiQ0HApoatj8xkD_3ahQzTpcf0JHEL4TlNFDtkGgfoUGf1N0VIWWKcSQ",
  "first_name": "John"
}

但是,我想要名字和名字,如:John Right

如何使用这个api获取整个名称,在我的iphone应用程序中它给出了全名,但没有在android中。

1 个答案:

答案 0 :(得分:0)

以下是显示Facebook好友的代码(可邀请 - 不安装您的应用)

它成功地给你的facebook朋友id,姓名和图片网址

private void loadFriendsFromFacebook(final FriendsLoadedCallback callback) {
    final Session session = Session.getActiveSession();

    new Request(session, "/me/invitable_friends", null, HttpMethod.GET, new Request.Callback() {
        public void onCompleted(Response response) {

            try {
                GraphObject graphObject = response.getGraphObject();
                JSONArray dataArray = (JSONArray) graphObject.getProperty("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(TAG_ID);

                        JSONObject picture_obj = object.getJSONObject(TAG_PICTURE);

                        JSONObject data_obj = picture_obj.getJSONObject(TAG_DATA);


                        String str_url = data_obj.getString(TAG_URL);
                        String str_name = object.getString(TAG_NAME);

                        System.out.println("fb id=" + str_id);
                        System.out.println("fb user name=" + str_name);
                        System.out.println("fb user image url =" + str_url);


                    } catch (Exception e) {

                    }

                }

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

        }
    }).executeAsync();

}