iOS Facebook SDK - 获取与App连接的好友列表

时间:2013-01-22 11:45:32

标签: ios objective-c facebook

我正在尝试获取所有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;
        }];

    }];

感谢。

5 个答案:

答案 0 :(得分: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;
            }];

     }];

答案 1 :(得分:7)

这可以用于最新的Facebook API 3.2,

[FBRequestConnection startForMyFriendsWithCompletionHandler:
     ^(FBRequestConnection *connection, id<FBGraphUser> friends, NSError *error)
     {
         if(!error){
             NSLog(@"results = %@", friends);
         }
     }
];

答案 2 :(得分: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"]);
                          }];
}

答案 3 :(得分:1)

你可以用FQL做到这一点。它将直接提供正在使用app的朋友列表。

SELECT uid FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ?)
AND is_app_user = 1

答案 4 :(得分:0)

应该关闭,因为Facebook已经改变了您访问好友列表的方式。 现在您可以访问的只是应用用户。