1

I have searched A LOT on the internet and I can't get this to work: How do i get an array of the user's facebook friends on iOS? All I need is an email address, full name and picture.

Here is what i have tried so far:

[FBSession openActiveSessionWithReadPermissions:[NSArray arrayWithObjects:@"read_friendlists", @"user_status", @"friends_status", nil] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
    if (!error) {
        FBRequest* friendsRequest = [FBRequest requestForMyFriends];
        friendsRequest.session = FBSession.activeSession;

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

}];}

The NSLogs don't log anything.

Now I get an error from the openActiveSessionWithReadPermissions call. It says:

Error Domain=com.facebook.sdk Code=2 "The operation couldn’t be completed. (com.facebook.sdk error 2.)" UserInfo=0x15673ed0 {com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginDisallowedWithoutError, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x15597540, state: FBSessionStateClosedLoginFailed, loginHandler: 0x0, appID: 603086539749721, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x155a9020>, expirationDate: (null), refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
4

1 回答 1

0

我认为系统不允许您的应用程序访问 Facebook。要解决此错误,请按照以下步骤操作:- 1. 转到 iPhone / iPad 的设置。2. 找出 Facebook 并转到其设置。3. 您会在列表中找到您的应用和其他应用。4. 请打开开关并尝试在您的应用中使用 Facebook。(默认情况下,它被系统关闭。所以你必须去设置并打开应用程序以允许访问 Facebook。)

希望它对你有用。谢谢你..!!

于 2014-06-11T07:35:33.427 回答