In the "old" FB iOS SDK I could receive user information via the following:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"SELECT uid, name, email, pic FROM user WHERE uid=me()", @"query",
                                   nil];
    JBFacebookManager *fbManager = [JBFacebookManager getInstance];
    fbManager.requestDelegate = self;
    [fbManager.facebook requestWithMethodName:@"fql.query"
                                     andParams:params
                                 andHttpMethod:@"POST"
                                   andDelegate:self];
How can I do this with the new FB iOS SDK 3.0? Do I need to use FBRequest or FBOpenGraphAction or FBGraphObject or a combination of those or something completely different?
if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
         if (!error) {
             self.nameLabel.text = user.name;
             self.emailLabel.text = [user objectForKey:@"email"];
         }
     }];
}
Because FBGraphUser doesn't have an email @property, we can't access the information like with the name (dot-syntax), however the NSDictionary still has the email kv-pair and we can access it like we would do with a normal NSDictionary.
Don't forget to ask for the email permission though:
NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
 ^(FBSession *session, FBSessionState state, NSError *error) {
     [self facebookSessionStateChanged:session state:state error:error];
 }];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With