我有这个片段
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
Bundle bundle = new Bundle();
bundle.putString("fields", "birthday");
mAsyncRunner.request("me/friends", bundle, new FriendListRequestListener());
它以某种方式工作,我的意思是我可以从我所有的朋友那里读取 ID。但是在我想阅读所有内容中,我该怎么做?
String _error = null;
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
for (int i = 0; i < friends.length(); i++) {
Log.v("id:", "id= "+friends.get(i).toString());
}
我应该怎么做才能获取有关我的朋友的信息并阅读该信息
我想这是关键,这是来自我找到的示例,它工作正常
bundle.putString("fields", "birthday");
但是当我举例说,不起作用
bundle.putString("fields", "friends_relationships");
-----------------编辑1-------------------------
权限代码
mFacebook.authorize(Example.this, new String[] {"offline_access", "user_interests", "friends_interests","friends_relationships","friends_relationship_details"},new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
-------------- 编辑 2 --------------
{"error":{"message":"必须使用活动访问令牌来查询有关当前用户的信息。","type":"OAuthException","code":2500}}
在大多数情况下,图形 API 是明智的选择。要检索您的好友信息,您需要先从用户那里收集一些扩展权限。然后,您可以检索除基本信息之外的更多信息。
以下是与朋友不同类型的信息相关的扩展权限列表
friends_about_me
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_notes
friends_online_presence
friends_photo_video_tags
friends_photos
friends_relationship_details
friends_relationships
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history
facebook.authorize(this, new String[] {"offline_access", "user_interests", "friends_interests"},
编辑:-
如果你的应用需要的不仅仅是这些基本信息才能运行,你可以 必须向用户请求特定权限。这是完成的 通过将权限的字符串 [] 传递给授权方法。这 以下示例演示如何请求访问用户的电子邮件地址, 获取扩展访问令牌并在某个位置签到用户:
facebook.authorize(this, new String[] { "email", "publish_checkins" },
new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
}
);
查看此处以获取更多详细信息。
编辑:-
mAsyncRunner.request("me/friends?fields=id,name,birthday,relationship_status", new FriendListRequestListener());
JSONObject json = Util.parseJson(response);
final JSONArray friends = json.getJSONArray("data");
for(int i=0;i<friends.length();i++)
{
JSONObject object = friends.getJSONObject(i);
Log.i("------------------ Id",object.getString("id"));
Log.i("------------------ Name",object.getString("name"));
Log.i("------------------ RelationShip",object.getString("relationship_status"));
}
您的朋友关系有单独的权限。 查看权限文档。
您需要请求 -
-
friends_relationships
-
friends_relationship_details
自 2015 年 5 月起,当 v1.0 facebook 图形 API 被弃用时,这现在的可能性更长。
试试这个:
Bundle params = new Bundle();
params.putString("fields", "name, picture, location");
mAsyncFacebook.request("me/friends",params, new RequestListener(){
@Override
public void onComplete(String response, Object object) {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
} catch (JSONException e) {
Log.d(TAG,"Exception :"+e);
}
}
}
要了解密钥,请参阅此链接:https://developers.facebook.com/docs/authentication/permissions/