我无法从 Facebook 用户那里检索 EMailID。我正在获得许可email
并登录以进行验证,因为它正在工作。但它不起作用。我不确定我哪里出错了。挣扎了很长时间。任何人都可以请帮帮我。以下是我的代码。在此先感谢。
-(IBAction)btnClicked{
// Initialize a session object
FBSession *session = [[FBSession alloc] init];
// Set the active session
[FBSession setActiveSession:session];
// Open the session
[session openWithBehavior:FBSessionLoginBehaviorWithFallbackToWebView
completionHandler:^(FBSession *session,
FBSessionState status,
NSError *error) {
// Respond to session state changes,
// ex: updating the view
if ([session isOpen]) {
// Session is open
NSArray *permissions = [NSArray arrayWithObjects:@"email", nil];
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:NO
completionHandler:
^(FBSession *session,
FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
NSLog(@"Session is open");
[self populateDetails];
} else {
// Session is closed
NSLog(@"Session is closed");
}
}];
}
-(void)populateDetails{
if (FBSession.activeSession.isOpen) {
[[FBRequest requestForMe]startWithCompletionHandler:^(FBRequestConnection *connection,NSDictionary<FBGraphUser> *user, NSError *error) {
if(!error){
NSLog(@"email %@",[user objectForKey:@"email"]);
}
else
{
NSLog(@"NW Issue");
}
}
}