Facebook的Android SDK中:得到共同的朋友
问题描述:
我想拿到两个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}
我做错了什么线索?
感谢
答
如果有人有兴趣,我终于被处理的请求作为图形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();
答
我知道它来不及回答这个问题,但我/ 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
谢谢!这个对我有用! – 2015-06-30 14:21:42
很高兴帮助你:) – 2015-06-30 14:29:38