Facebook access token nil after app relaunch

谁都会走 提交于 2019-12-11 06:14:32

问题


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) :

  1. save "access token" in firebase database at fb login
  2. when app restart, get the persisted "access token" from database
  3. check if the "access token" is still valid
  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!