问题
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 :
An active access token must be used to query information about the current user.
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) ?
My solution (but don't know if best way) :
- save "access token" in firebase database at fb login
- when app restart, get the persisted "access token" from database
- check if the "access token" is still valid
- if not, re-log user and get a new "access token" and save it
Update
I noticed that i was getting this message :
Falling back to loading access token from NSUserDefaults because of simulator bug
so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.
回答1:
I noticed that I was getting this message :
Falling back to loading access token from NSUserDefaults because of simulator bug
so I checked my code in a real device, and it's working now, the access token is persisted through the app relaunch.
来源:https://stackoverflow.com/questions/44166152/facebook-access-token-nil-after-app-relaunch