2

Android SDKを使用して、2人の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

誰かが興味を持っているなら、私は最終的にリクエストをGraphAPIリクエストとして扱うことでこれを解決しました:

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

この質問に答えるには遅すぎることはわかっていますが、me / mutualfriends/otherUserIdはFacebookGraphAPI v2.0以降では非推奨になっているため、これはGraphAPIv2.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 に答える