
Question:
I'm developing an app on iOS with Firebase Auth and Facebook. I want to use Facebook graph sdk after login with Facebook. It's working fine the first time. But when I re-launch the app, the graph API don't work :
<blockquote>An active access token must be used to query information about the current user.
</blockquote>and the following code is nil :
FBSDKAccessToken.current()?.tokenString
BUT the user is logged with Firebase Auth :
// check if user is logged
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if user != nil{
print("User logged") ...
Is there a way to get the current Facebook access token via Firebase Auth ? Or I have to persist the access token for using it later ? Or re-log user each time (not user friendly at all) ?
<strong>My solution (but don't know if best way) :</strong>
<ol><li>save "access token" in firebase database at fb login </li> <li>when app restart, get the persisted "access token" from database</li> <li>check if the "access token" is still valid </li> <li>if not, re-log user and get a new "access token" and save it</li> </ol><strong>Update</strong>
I noticed that i was getting this message :
<blockquote>Falling back to loading access token from NSUserDefaults because of simulator bug
</blockquote>so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.
Answer1:I noticed that I was getting this message :
<blockquote>Falling back to loading access token from NSUserDefaults because of simulator bug
</blockquote>so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.