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

时间:2014-01-06 09:15:09

标签: ios facebook facebook-graph-api

我正在使用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的响应之后将出现空白屏幕而不返回App。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分: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