通过应用程序使用 FB 中未经验证的用户帐户登录 Facebook

问题描述 投票:0回答:1

我正在使用 facebook-ios-sdk-3.10,使用此 SDK 我将登录并从 FB 获取用户详细信息,它对我来说工作正常。

这是我正在使用的代码

- (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 帐户”并且它不会返回到我的应用程序。我怎样才能从那里获取响应?参考屏幕简短。

enter image description here

enter image description here

我提供了登录详细信息,单击登录按钮后,将出现空白屏幕,此后 SDK 没有响应并且不会返回到应用程序。

有人可以帮我吗?

ios facebook facebook-graph-api
1个回答
0
投票

将此代码添加到您的 AppDelegate

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [FBSession.activeSession handleOpenURL:url];
} 

了解更多:https://developers.facebook.com/docs/ios/login-tutorial

© www.soinside.com 2019 - 2024. All rights reserved.