0

我无法从 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");
    }
  }
}
4

2 回答 2

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];
 }];
于 2013-10-08T07:15:25.633 回答
0

我想你得试试这个

` self.fbGraph = [[FbGraph alloc] initWithFbClientID:kFacebookAppId]; if ( (fbGraph.accessToken == nil) || ([fbGraph.accessToken 长度] == 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"

于 2013-10-08T11:58:39.533 回答