9

我正在尝试获取正在使用该应用程序的所有 Facebook 朋友的列表 我正在获取所有朋友的列表,但是如何过滤所有正在使用该应用程序的朋友?

    FBRequest* friendsRequest = [FBRequest requestForMyFriends];
    [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                  NSDictionary* result,
                                                  NSError *error) {
        NSArray* friends = [result objectForKey:@"data"];
        NSLog(@"Found: %i friends", friends.count);
        for (NSDictionary<FBGraphUser>* friend in friends) {
            NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);

        }
        NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
            return friend.id;
        }];

    }];

谢谢。

4

5 回答 5

7

这就是它在 iOS5+ 上的工作方式

FBRequest* friendsRequest = [FBRequest requestWithGraphPath:@"me/friends?fields=installed" parameters:nil HTTPMethod:@"GET"];
        [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                      NSDictionary* result,
                                                      NSError *error) {
            NSArray* friends = [result objectForKey:@"data"];
            NSLog(@"Found: %i friends", friends.count);
            for (NSDictionary<FBGraphUser>* friend in friends) {
                NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);

            }
            NSArray *friendIDs = [friends collect:^id(NSDictionary<FBGraphUser>* friend) {
                return friend.id;
            }];

     }];
于 2013-01-22T12:46:52.913 回答
7

这可用于最新的 Facebook API 3.2 ,

[FBRequestConnection startForMyFriendsWithCompletionHandler:
     ^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
     {
         if(!error){
             NSLog(@"results = %@", friends);
         }
     }
];
于 2013-09-27T06:59:16.303 回答
2

您需要检查的“is_app_user”。

- (void)getFriends
{

    NSString *query = @"select uid, name, is_app_user "
    @"from user " 
    @"where uid in (select uid2 from friend where uid1=me() )";
    NSDictionary *queryParam =
    [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
    // Make the API request that uses FQL
    [FBRequestConnection startWithGraphPath:@"/fql"
                                 parameters:queryParam
                                 HTTPMethod:@"GET"
                          completionHandler:^(FBRequestConnection *connection,
                                              id result,
                                              NSError *error) {
                              if (error) {
                                  DLog(@"Error: %@", [error localizedDescription]);
                                  [self.delegate FBDidFailedLoadFriends:error];
                              } else { 
                                  DLog(@"Result: %@", result);
                              }
                              DLog(@"%@",((FBGraphObject*)result)[@"data"]);
                          }];
}
于 2013-12-08T09:35:37.263 回答
1

你可以用 FQL 做到这一点。它将直接给出正在使用应用程序的朋友列表。

SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ?)
AND is_app_user = 1
于 2013-01-22T12:27:00.513 回答
0

应该关闭,因为 Facebook 改变了您访问朋友列表的方式。现在您只能访问应用程序用户。

于 2017-08-14T13:36:08.087 回答