如何使用新图API获取Facebook好友列表

时间:2011-08-17 17:16:04

标签: iphone objective-c facebook-graph-api

我目前正在开发一款应用程序,我需要使用新的facebook图谱API从Facebook好友列表中添加朋友。

这是我的代码:

 _permissions = [[NSArray arrayWithObjects:
                         @"read_stream", @"publish_stream", @"offline_access",@"read_friendlists",nil] retain];

[facebook authorize:_permissions];

facebook = [[Facebook alloc] initWithAppId:@"fbid" andDelegate:self];


[facebook requestWithGraphPath:@"me" andDelegate:self];
[facebook requestWithGraphPath:@"me/friends" andDelegate:self];
NSMutableDictionary*params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"4",@"uids", @"name", @"fields", nil];
[facebook requestWithMethodName:@"user.getInfo" andParams:params andHttpMethod:@"GET" andDelegate:self];

但每次它在控制台上给我错误 请帮帮我......

2 个答案:

答案 0 :(得分:3)

这里有一个提取朋友信息的代码示例:

        [facebook requestWithGraphPath:@"me/friends" 
                             andParams:[ NSDictionary dictionaryWithObjectsAndKeys:@"picture,id,name,link,gender,last_name,first_name",@"fields",nil]
                           andDelegate:self];

请记住:

  1. 实施适当的委托方法
  2. 您必须在获取好友信息之前调用authorize。这样用户就可以先登录了。
  3. 我希望这会有所帮助,欢呼

答案 1 :(得分:-1)

   $friend_list =json_decode(file_get_contents("https://graph.facebook.com/$uid/friendlists?access_token=$access_token"),true);
   $friend_list_array = $friend_list['data'];
    foreach($friend_list_array as $key=> $value){
$inner_array_name[$value['id']][]=$value['name'];
        }