2

我正在尝试使用 Android SDK 获得两个 Facebook 用户的共同朋友:

Request friendsInCommon = Request.newRestRequest(myFbSession, "me/mutualfriends/otherUserId", null, HttpMethod.GET);

但是,这会返回以下错误:

03-16 04:24:39.652: D/ViewProfile(27121): My friends list: {Response:  responseCode: 200, graphObject: null, error: {HttpStatus: 200, errorCode: 3, errorType: null, errorMessage: Unknown method}, isFromCache:false}

关于我做错了什么的任何线索?

谢谢

4

2 回答 2

2

如果有人感兴趣,我最终通过将请求视为 Graph API 请求来解决这个问题:

Bundle params = new Bundle();
params.putString("fields", "id,name,picture");
Request req = new Request(myFbSession, "me/mutualfriends/otherUserId", params, HttpMethod.GET, new Callback(){
    @Override
    public void onCompleted(Response response) {
        // your callback code
    }
});
req.executeAsync();
于 2013-03-17T03:42:09.087 回答
1

我知道回答这个问题为时已晚,但我/mutualfriends/otherUserId在 Facebook Graph API v2.0 及更高版本中已弃用,因此这是在 Graph API v2.0 及更高版本中获取共同朋友的正确方法

Bundle params = new Bundle();
            params.putString("fields", "context.fields(mutual_friends)");
            new GraphRequest(
                    AccessToken.getCurrentAccessToken(),
                    "/" + fbId,
                    params,
                    HttpMethod.GET,
                    new GraphRequest.Callback() {
                        @Override
                        public void onCompleted(GraphResponse graphResponse) {
                            try {
                                JSONObject jsonObject = new JSONObject(graphResponse.getRawResponse());
                                if (jsonObject.has("context")) {
                                   jsonObject = jsonObject.getJSONObject("context");
                                if (jsonObject.has("mutual_friends")) {
                                    JSONArray mutualFriendsJSONArray = jsonObject.getJSONObject("mutual_friends").getJSONArray("data");
                                  // this mutualFriendsJSONArray contains the id and name of the mutual friends.
                                }
                              }
                            } catch (JSONException e) {
                                e.printStackTrace();
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
            ).executeAsync();

有关官方文档,请参阅此https://developers.facebook.com/docs/graph-api/reference/v2.3/user.context/mutual_friends

于 2015-06-12T05:47:02.883 回答