Reputation: 1722
I am a beginner in iOS development. I searched a lot but didn't get my code working cause of some deprecated class in latest fbsdk 4.2. What i want is that integration of fb in my apps. I am Able to integrate fb in my app and i can successfully login and logout. Now my app need is to fetch the logged-in user e-mail id and display it in a label. Here is my code, which i have tried.
-(void)viewDidLoad {
[super viewDidLoad];
if ([FBSDKAccessToken currentAccessToken]) {
self.loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"me"
parameters:@{@"fields":@"email"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
id result,
NSError *error) {
if(!error)
{
self.lblEmail.text = [result objectForKey:@"email"];
NSLog(@"email:%@", result);
}
}];
}
Upvotes: 0
Views: 170
Reputation: 286
this is working fine with me for facebook sdk 4.2
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler: ^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error)
NSLog(@"%@",result);
else
NSLog(@"%@",error);
}];
}
Hope this will help you.
Upvotes: 1