FBSDKProfile currentProfile是nil但是FBSDKAccessToken currentAccessToken有值

时间:2015-07-21 12:03:05

标签: ios objective-c facebook facebook-sdk-4.0

就像标题所说的那样,这是一个错误还是真的可能?我使用[FBSDKAccessToken currentAccessToken].tokenString检查现有的Facebook会话是否存在,然后我将使用[FBSDKProfile currentProfile].userID来获取会话的userId。 但有时我会遇到[FBSDKAccessToken currentAccessToken].tokenString有值,但[FBSDKProfile currentProfile]为零。

我将此用于我的应用程序的自动登录功能。

感谢您的回复!

所以我有这段代码:

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

该日志的返回为零。

2 个答案:

答案 0 :(得分:1)

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

您需要致电[FBSDKProfile enableUpdatesOnAccessTokenChange:YES],以便自动观察对[FBSDKAccessToken currentAccessToken]

的更改

答案 1 :(得分:0)

您可能需要加载当前配置文件,使用以下代码段,在回调运行之后,除非没有当前令牌,否则您将获取配置文件数据。 enter image description here