2013-03-16 58 views
2

我想拿到兩個Facebook用戶的共同的朋友,使用Android SDK:Facebook的Android SDK中:得到共同的朋友

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} 

我做錯了什麼線索?

感謝

回答

2

如果有人有興趣,我終於被處理的請求作爲圖形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(); 
1

我知道它來不及回答這個問題,但我/ mutualfriends/otherUserId在Facebook的圖形API 2.0版已被棄用以上,所以這是獲得圖形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

+0

謝謝!這個對我有用! – 2015-06-30 14:21:42

+0

很高興幫助你:) – 2015-06-30 14:29:38