簡體   English   中英

如何使用新圖 API 獲取 facebook 朋友列表

[英]how to get facebook friend list using new 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];

但每次它給我控制台錯誤
請幫我...

這里有一個獲取朋友信息的代碼示例:

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

記得:

  1. 實現正確的委托方法
  2. 在獲取好友信息之前,您必須調用 authorize。 這樣用戶就可以先登錄。

我希望這會有所幫助,干杯

我覺得你應該換。 否則它不起作用。

這是正確的方法:

 facebook = [[Facebook alloc] initWithAppId:@"fbid" andDelegate:self];
 [facebook authorize:_permissions];
   $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'];
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM