2016-02-17 53 views
0

下面是我的代码获得Facebook的朋友登录的用户。获取与Parse.com iOS版Facebook好友

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/friends" parameters:@{@"fields": @"email, name, first_name, last_name, user_friends, id"}]; 
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) 
    { 
     if (!error) 
     { 
      NSArray *friendObjects = [result objectForKey:@"data"]; 
      NSMutableArray *friendIds = [NSMutableArray arrayWithCapacity:friendObjects.count]; 
      // Create a list of friends' Facebook IDs 
      for (NSDictionary *friendObject in friendObjects) { 
       [friendIds addObject:[friendObject objectForKey:@"id"]]; 
      } 

      // Construct a PFUser query that will find friends whose facebook ids 
      // are contained in the current user's friend list. 
      PFQuery *friendQuery = [PFUser query]; 
      [friendQuery whereKey:@"fbId" containedIn:friendIds]; 
      [friendQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { 
       if (error) { 

       } else { 
        self.friendUsers = objects; // self.friendUsers in array 
        [self.tableView reloadData]; 
       } 
      }]; 

     } 
    }]; 

林没有得到任何结果和IM不知道为什么我遵循的步骤在这里https://parse.com/questions/how-can-i-find-parse-users-that-are-facebook-friends-with-the-current-user

请帮忙

+0

您是否有任何朋友已经是同一个应用程序的用户,并且已授予'user_friends'权限? – CBroe

+0

@CBroe嗨非我的Facebook的朋友正在使用的应用程序,解释了为什么大声笑。但是,如果代码工作包括这个'initWithGraphPath:@“/ me/friends”' – Joey121

+0

我想它应该(尽管我对Android应用程序没有什么经验)。我建议你通过应用程序仪表板创建一些测试用户,让他们成为朋友,然后使用其中一个测试你的应用程序。 – CBroe

回答

1

user_friends Facebook权限只返回已批准应用程序的user_friends权限的用户的朋友。

为了让一个人在一个人的好友列表中显示,这两个 人必须决定与你的应用程序 分享他们的好友列表和登录过程中没有禁用该权限。在登录过程中,两个朋友必须 都被要求提供user_friends。 1

因此,除非您的某些Facebook朋友已经批准了该应用的权限,否则您将收到一个空的朋友列表。