简体   繁体   中英

Login via facebook sdk in ios

I'm using facebook-ios-sdk-3.10, Using this SDK I'll login and fetch user details from FB Its working fine for me.

This is the code I'm 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];
        }];
    }
}

In such case some user create Facebook account and not very his account through email, when he try to login via my app it shows empty screen after click login button, there is no action further. how can I notify the user "You not yet verify your FB account" and it not return to my app. how can I fetch the response from there ?

can anyone help me for this ?

The email address you get from Facebook using the Graph API or a FQL query is a verified email. If an account hasn't verified it's email yet it's not possible to get it.

so when you fetch user info and if you are not getting the email when you have the permission to get then user is no verified and you can show an alert or any info to user about verifying the email and information

check more detail here Is it possible to check if an email is confirmed on Facebook?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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