繁体   English   中英

在iOS中通过Facebook SDK登录

[英]Login via facebook sdk in ios

我正在使用facebook-ios-sdk-3.10,使用此SDK,我将登录并从FB获取用户详细信息。

这是我的uisng代码

- (IBAction)fbLogin_click:(id)sender
{
    if (AppDelegate.fbsession.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        NSArray *permissions = [NSArray arrayWithObjects:@"offline_access", @"email", @"publish_stream", @"read_stream",@"read_friendlists",@"manage_friendlists",@"friends_about_me",@"publish_actions", nil];

        // create a session object, with defaults accross the board, except that we provide a custom
        // instance of FBSessionTokenCachingStrategy
        AppDelegate.fbsession = [[FBSession alloc] initWithAppID:nil
                                                   permissions:permissions
                                               urlSchemeSuffix:nil
                                            tokenCacheStrategy:nil]; 
    }


    FBSessionLoginBehavior behavior = FBSessionLoginBehaviorForcingWebView; 
    if (AppDelegate.fbsession.state != FBSessionStateCreatedTokenLoaded) {

        // even though we had a cached token, we need to login to make the session usable
        [AppDelegate.fbsession openWithBehavior:behavior completionHandler:^(FBSession *session,
                                                                           FBSessionState status,
                                                                           NSError *error) {
            if (error)
            {
                NSLog(@"Error");
            }

            [self GetFBUserDetails];
        }];      
    }
} 

-(void) GetFBUserDetails
{
    if (AppDelegate.fbsession.isOpen)
    {
        [HUD show:YES];
        // fetch profile info such as name, id, etc. for the open session
        FBRequest *me = [[FBRequest alloc] initWithSession:AppDelegate.fbsession graphPath:@"me"];

        self.pendingRequest= me;

        [me startWithCompletionHandler:^(FBRequestConnection *connection,
                                         NSDictionary<FBGraphUser> *user,
                                         NSError *error) {
            // because we have a cached copy of the connection, we can check
            // to see if this is the connection we care about; a prematurely
            // cancelled connection will short-circuit here
            if (me != self.pendingRequest) {
                return;
            }

            self.pendingRequest = nil;
            //            self.pendingLoginForSlot = -1;

            // we interpret an error in the initial fetch as a reason to
            // fail the user switch, and leave the application without an
            // active user (similar to initial state)
            if (error) {

                return;
            }

            [AppDelegate.fbsession closeAndClearTokenInformation];
            [FBSession.activeSession close];
            [FBSession.activeSession  closeAndClearTokenInformation];
            FBSession.activeSession=nil;

            [self FacebookCustomerRegister:user];
        }];
    }
}

在这种情况下,某些用户创建Facebook帐户而不是通过电子邮件创建他的帐户,当他尝试通过我的应用程序登录时,单击“登录”按钮后显示空白屏幕,则没有进一步的操作。 我如何通知用户“您尚未验证FB帐户”,并且该帐户不返回我的应用程序。 我如何从那里获取响应?

有人可以帮我吗?

您使用Graph API或FQL查询从Facebook获得的电子邮件地址是经过验证的电子邮件。 如果帐户尚未验证,则为电子邮件,但无法获取。

因此,当您获取用户信息时,如果您没有获得电子邮件的权限,那么该用户将无法通过验证,并且可以向用户显示有关验证电子邮件和信息的警报或任何信息

在此处检查更多详细信息是否可以检查Facebook上是否已确认电子邮件?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM