iOS FB SDK Access Token is nil

183 Views Asked by At

I'm using FBSDKCoreKit and FBSDKLoginKit v13.1

I have a FB Login Button in my application with the following handler:

- (void)  loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
                error:(NSError *)error{
    if (error || (result && result.isCancelled)) {
      return;
    }
    [self loginWithFB];
}

This part of the code works fine, the buttons state also changes to Log out after a successful login, however when I want to make graph requests they fail because it doesn't have a FB Access token ([FBSDKAccessToken currentAccessToken] is nil)

- (void) loginWithFB {
    NSString *fbAccessToken = [[FBSDKAccessToken currentAccessToken] tokenString];

    [[[FBSDKGraphRequest alloc]
      initWithGraphPath:@"me"
      parameters:@{@"fields": @"id"}
      tokenString:fbAccessToken
      version:nil
      HTTPMethod:@"GET"
     ]
     startWithCompletion:^(id<FBSDKGraphRequestConnecting> connection, id result, NSError *error) {
        if (!error) {
            ...
        } else {
            ...
        }
     }];
}

I am not sure what is causing this, the bootstrap (AppDelegate, plist, etc.) setup for the FB SDK is set up correctly (checked this more than I would like), but the docs clearly state that when the button has a logged in state, the currentAccessToken should be available. (FBSDKLoginManager works directly with [FBSDKAccessToken currentAccessToken] and sets the "currentAccessToken" upon successful authorizations (or sets nil in case of logOut).)

0

There are 0 best solutions below