FB用户电子邮件ID不是提取

时间:2013-10-08 07:05:49

标签: ios objective-c xcode facebook

我无法从Facebook用户检索EMailID。我正在获取email的权限并登录进行验证,因为它正在工作。但它无法正常工作。我不确定我哪里出错了。很长一段时间。任何人都可以帮帮我。以下是我的Code.Thanks in Advance。

-(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");
    }
  }
}

2 个答案:

答案 0 :(得分:1)

检查一下

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"];
             }
         }];
    }




NSArray *permissions = [[NSArray alloc] initWithObjects:@"email", nil];
[FBSession sessionOpenWithPermissions:permissions completionHandler:
 ^(FBSession *session, FBSessionState state, NSError *error) {
     [self facebookSessionStateChanged:session state:state error:error];
 }];

答案 1 :(得分:0)

我认为你必须尝试这个

`  self.fbGraph = [[FbGraph alloc] initWithFbClientID:kFacebookAppId];  if((fbGraph.accessToken == nil)||([fbGraph.accessToken length] == 0))

    {

        [fbGraph authenticateUserWithCallbackObject:self andSelector:@selector(fbGraphCallback:)

                             andExtendedPermissions:CFacebookPermissions];

    }

否则

    {

        [self performSelector:@selector(fbGraphCallback:) withObject:nil afterDelay:0.000000000001];

    }

`

并且允许设置此

定义CFacebookPermissions @“publish_stream,offline_access,user_checkins,friends_checkins,read_stream,email”