This is what I use in my apps, you have to allow the login UI.
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI completionHandler:(FBSessionStateHandler)handler {
// We pass this permissions array into our request.
// I only request email, but there are many more options.
//
NSArray *permissions = @[@"email", @"basic_info"];
return [FBSession
openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
if (handler)
handler(session, state, error);
}];
}
And that's how you use it
[self openSessionWithAllowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
if (!error && status == FBSessionStateOpen) {
NSString *token = session.accessTokenData.accessToken;
// You're logged in!
} else {
// Something wrong happened
}
}];