Unable to Get the Access Token Through [Fbsdkaccesstoken Currentaccesstoken] in iPhone Sdk

FBSDKAccessToken currentAccessToken is not being updated after log in

Please check your appDelegate class and implement all the required methods of FB SDK. I am attaching a screenshot for the same.

Sample Image

How to get FBSDKAccessToken from FBSDKAuthenticationToken

According to this blog post of Facebook, limited mode and classic mode use different authentication methods behind.

Limited Login mode is based on the OpenID Connect standard.
Classic Login mode utilizes oAuth 2.0.

Therefore, I think there's no way to get access token by authentication token.
But we can get basic profile of user under limited login mode. There's a code snippet from Facebook's documentation reveals how to do that.

let loginManager = LoginManager()

// Ensure the configuration object is valid
guard let configuration = LoginConfiguration(tracking: .limited, nonce: "123")
else {
return
}

loginManager.logIn(configuration: configuration) { result in
switch result {
case .cancelled, .failed:
// Handle error
break
case .success:
// getting user ID
let userID = Profile.current?.userID

// getting pre-populated email
let email = Profile.current?.email

// getting id token string
let tokenString = AuthenticationToken.current?.tokenString
}
}

Also note that limited login mode does not support Graph API.

Why is [FBSDKAccessToken currentAccessToken] is nil after login in with permissions

For anyone, browsing though this, I was using FSDKLoginButton as an instance variable in order to access it through different routines. That is why it wasn't working. You have to declare the button as google said.

Error:An active access token must be used to query information about the current user

Got it!

This will be surely helpful to someone, Actually i did mistake in this place, [[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"}] This method not have the access token ever. But wonder is the access token is not enable in the whole app. it will be null when i move to the next page after kill the app. So i just save the token string in NSUserDefaults like

NSString *access_token=[FBSDKAccessToken currentAccessToken].tokenString;
[NSUSER setObject:access_token forKey:@"fb_token"];
[NSUSER synchronize];

And then wherever i call the graphAPI i use this method with tokenstring like,

[[[FBSDKGraphRequest alloc] initWithGraphPath:url parameters:@{ @"fields": @"id,picture"} tokenString:[NSUSER objectForKey:@"fb_token"] version:nil HTTPMethod:@"GET"]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error)
{
}];

Simple but it takes too long to find. Glad!



Related Topics



Leave a reply



Submit