应用重新启动后,Facebook访问令牌为零 [英] Facebook access token nil after app relaunch
问题描述
$ b
必须使用活动访问令牌来查询有关
当前用户
以下代码为零:
FBSDKAccessToken.current()?。tokenString
用户使用Firebase身份验证进行日志记录:
//检查用户是否登录
FIRAuth.auth()?. addStateDidChangeListener({(auth,user)in
if user!= nil {
print(User logged)...
有没有办法通过Firebase身份验证获取当前的Facebook访问令牌?
或者我必须保留访问令牌以便稍后使用它或每个用户重新登录我的解决方案(但不知道是否最好的方法):
$ b
- 在fb登录时将firebase数据库中的访问令牌保存到
- 当应用程序恢复rt,从数据库获取持久化的访问令牌
- 检查访问令牌是否仍然有效如果不是,则重新记录用户并获取一个新的访问令牌并将其保存
更新
我注意到我得到这个消息:
lockquote
由于$ b,回退到加载NSUserDefaults的访问标记$ b模拟器bug
所以我在真实设备中检查了我的代码,现在它正在工作,访问令牌通过应用程序持久化重新启动。
我注意到我得到这个消息:
$ b $
因为
模拟器错误而退回到从NSUserDefaults加载访问标记
我的代码在一个真实的设备,它现在正在工作,访问令牌是通过应用程序重新启动持久。
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.
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.
这篇关于应用重新启动后,Facebook访问令牌为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!