1

我正在尝试获取用户的朋友列表。我在 FacebookSDK 3.12 中实现的最后一个工作代码现在没用了,因为 facebook 已经更改了所有的类,甚至删除了旧的类,下面是我的旧代码:

#pragma mark - Facebook Methods -
-(void)initiateFacebookSessionIfNot
{
    if (FBSession.activeSession.isOpen)
    {
        [self getUserFriendsIds];
    } else
    {
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_birthday",@"friends_hometown",
                                @"friends_birthday",@"friends_location",
                                nil];
        [FBSession openActiveSessionWithReadPermissions:permissions allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status,NSError *error)
         {
             if (error) {
                 NSString *alertMessage, *alertTitle;

                 if (error.fberrorShouldNotifyUser) {
                     alertTitle = @"Something Went Wrong";
                     alertMessage = error.fberrorUserMessage;
                 } else if (error.fberrorCategory == FBErrorCategoryUserCancelled) {
                     NSLog(@"user cancelled login");
                 } else {
                     // For simplicity, this sample treats other errors blindly.
                     alertTitle  = @"Unknown Error";
                     alertMessage = @"Error. Please try again later.";
                     NSLog(@"Unexpected error:%@", error);
                 }

                 if (alertMessage)
                 {
                     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:alertTitle
                                                                     message:error.fberrorUserMessage
                                                                    delegate:nil
                                                           cancelButtonTitle:@"OK"
                                                           otherButtonTitles:nil];
                     [alert show];
                 }
             } else if (FB_ISSESSIONOPENWITHSTATE(status)) {
                 [self getUserFriendsIds];
             }
         }];
    }
}
-(void)getUserFriendsIds
{
    FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,username"];
    [ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        NSMutableArray *fbFriendIDs;
        NSMutableArray *fbFriendsName;
        NSMutableArray *fbFriendsUserName;

        NSMutableArray *data = [[NSMutableArray alloc]initWithArray:[result objectForKey:@"data"]];
        [data enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
            if (!(NSDictionary*)obj[@"username"]) {

                NSDictionary *newDictionary =@{@"id": (NSDictionary*)obj[@"id"],
                                               @"name": (NSDictionary*)obj[@"name"],
                                               @"username": @"0"
                                               };
                [data replaceObjectAtIndex:idx withObject:newDictionary];
            }
        }];

        fbFriendsUserName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.username"]];
        fbFriendsName = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.name"]];
        fbFriendIDs = [[NSMutableArray alloc]initWithArray:[data valueForKeyPath:@"@unionOfObjects.id"]];

        NSDictionary *queryDictionary =
        @{@"user_id": userObj.user_id,
          @"friend_ids":[fbFriendIDs componentsJoinedByString:@","],
          @"names":[fbFriendsName componentsJoinedByString:@","],
          @"usernames":[fbFriendsUserName componentsJoinedByString:@","]
          };

        [[RequestHandler sharedClient] CheckFBFriendsWithDictionary:queryDictionary WithCompletionBlock:^(NSArray *TUNFriendsArray, NSArray *FBFriendsArray, NSString *errorMessage) {
            if (!errorMessage) {

                tunFriendsArray = [[NSMutableArray alloc]initWithArray:TUNFriendsArray];
//                fbFriendsArray = [[NSMutableArray alloc]initWithArray:FBFriendsArray];

                [_facebookTableView reloadData];
            }
            else{
                [ApplicationUtilities ShowAlertViewWithTitle:APP_NAME Message:errorMessage];
            }
        }];
    }];
    [SVProgressHUD dismiss];
}
4

2 回答 2

1

不再可能接收该username字段,以及除 public_profile 之外的用户朋友的所有信息,因为friends_*从 v2.0 开始,所有权限已被删除。

此外,您不会收到完整的朋友列表,而只会收到那些也使用您的应用程序的朋友。

引号:

  • /me/username不再被提供。

  • /me/friends端点不再包括一个人的朋友的完整列表。相反,它现在会返回该人也在使用您的应用程序的朋友列表。

  • 所有friends_*权限均已删除。

于 2015-03-30T09:33:56.823 回答
1

Facebook 在其新版本(即 V2.0)中更改了很多实现,其中Tag-gable Friends APIInvitable Friend APISocial Context APIBusiness Mapping APITagged Places API是新功能。他们还进行了许多权限更改,以提高安全性,请从以下链接阅读更多内容

希望您能从上述链接中找到所需的实施更改。

于 2015-03-31T07:52:43.997 回答