简体   繁体   中英

FBSDKProfile currentProfile is nil but FBSDKAccessToken currentAccessToken has value

Just like what the title says, is this a bug or is it really possible? I use the [FBSDKAccessToken currentAccessToken].tokenString to check whether an existing Facebook session is existing, then afterwards I'll use the [FBSDKProfile currentProfile].userID to get the session's userId. However sometimes I encounter that [FBSDKAccessToken currentAccessToken].tokenString has a value but [FBSDKProfile currentProfile] is nil.

I use this for the auto-login feature of my application.

Thanks for your response!

So I have this code snippet:

    if ([FBSDKAccessToken currentAccessToken].tokenString){
//proceed to auto login since Facebook is still logged in
        NSLog(@"Facebook user id: %@",[FBSDKProfile currentProfile].userID)
    }

The return of that log is nil.

if ([FBSDKAccessToken currentAccessToken].tokenString) {
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES];
    NSLog(@"Facebook user id: %@",[FBSDKProfile currentProfile].userID);
}

you need to call [FBSDKProfile enableUpdatesOnAccessTokenChange:YES] so that it automatically observes changes to the [FBSDKAccessToken currentAccessToken]

You may need to load the current profile, use this following snippet, after the callback runs you will get the profile data unless you don't have current token. 在此输入图像描述

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