ios - Not getting email id when login via FacebookSDK.framework -
in application doing login facebook via facebooksdk.framework
- (ibaction)facebookloginbtn1:(id)sender { [fbsession openactivesessionwithreadpermissions:@[@"email"] allowloginui:yes completionhandler: ^(fbsession *session, fbsessionstate state, nserror *error) { appdelegate* appdelegate = [uiapplication sharedapplication].delegate; [appdelegate sessionstatechanged:session state:state error:error]; [[fbrequest requestforme] startwithcompletionhandler: ^(fbrequestconnection *connection, nsdictionary<fbgraphuser> *user, nserror *error) { if (!error) { nsstring *firstname = user.first_name; nsstring *lastname = user.last_name; nsstring *facebookid = user.id; nsstring *email = [user objectforkey:@"email"]; nsstring *imageurl = [[nsstring alloc] initwithformat: @"http://graph.facebook.com/%@/picture?type=large", facebookid]; nslog(@"%@",email); nslog(@"%@",user.id); nslog(@"%@",imageurl); } else { } }]; }];
}
and code working in old application , getting fb id , user name here. have tried diffrent types of permissions , facebook id's can not able find out problem here .
i have done whole set in info plist , facebook developer portle. getting below response fbgraphuser object
{ id = fb id; name = “user name here“;}
as responce . here no email id getting. can 1 me out here. supposed minor thing missing.
try code. based on facebook sdk version 4.0
viewcontroller.m
- (ibaction)btnfacebookpressed:(id)sender { fbsdkloginmanager *login = [[fbsdkloginmanager alloc] init]; [login loginwithreadpermissions:@[@"email"] handler:^(fbsdkloginmanagerloginresult *result, nserror *error) { if (error) { // process error } else if (result.iscancelled) { // handle cancellations } else { if ([result.grantedpermissions containsobject:@"email"]) { nslog(@"result is:%@",result); [self fetchuserinfo]; } } }]; } -(void)fetchuserinfo { if ([fbsdkaccesstoken currentaccesstoken]) { nslog(@"token available : %@",[[fbsdkaccesstoken currentaccesstoken]tokenstring]); [[[fbsdkgraphrequest alloc] initwithgraphpath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}] startwithcompletionhandler:^(fbsdkgraphrequestconnection *connection, id result, nserror *error) { if (!error) { nslog(@"resultis:%@",result); } else { nslog(@"error %@",error); } }]; } }
viewdidload
call method access token after login
[self fetchuserinfo];
pass parameter way email, name etc..
@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}
Comments
Post a Comment