The new Facebook SDK for iOS has a convenient way to access user information via the
FBGraphUser protocol in a nice "dot-syntax" manner. However, because the FBGraphUser protocol doesn't have an email @property, we can't access all the information like we do with the name (see example below). Nevertheless, as with the previous SDK, the NSDictionary still contains the email kv-pair and other user information, which is not populated via the FBGraphUser protocol and we can access it like we would have done it with a normal NSDictionary (since it still is just a normal NSDictionary).
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary *user, NSError *error) {
if (!error) {
self.nameLabel.text = user.name;
self.emailLabel.text = [user objectForKey:@"email"];
}
}];
}
Also, don't forget to ask for the email
permission when opening the FB session:
NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self facebookSessionStateChanged:session state:state error:error];
}];
Source:
stackoverflow.com
No comments:
Post a Comment