繁体   English   中英

Android me / invitable_friends Facebook API仅返回名字

[英]Android me/invitable_friends facebook api returns only first name

我开发了一个应用

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

使用以下代码,

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

如何在我的iPhone应用程序中使用此api获取全名,但在android中不提供全名。

以下是显示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();

}

暂无
暂无

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

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