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)>}