应用重新启动后,Facebook访问令牌为零 [英] Facebook access token nil after app relaunch

查看:269
本文介绍了应用重新启动后,Facebook访问令牌为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Auth和Facebook在iOS上开发应用程序。我想用Facebook登录后使用Facebook图形SDK。这是第一次正常工作。但是,当我重新启动应用程序时,图API不起作用:
$ b


必须使用活动访问令牌来查询有关
当前用户


以下代码为零:

  FBSDKAccessToken.current()?。tokenString 

用户使用Firebase身份验证进行日志记录:

  //检查用户是否登录
FIRAuth.auth()?. addStateDidChangeListener({(auth,user)in
if user!= nil {
print(User logged)...

有没有办法通过Firebase身份验证获取当前的Facebook访问令牌?
或者我必须保留访问令牌以便稍后使用它或每个用户重新登录我的解决方案(但不知道是否最好的方法):

$ b的时间(根本不是用户友好的)?


$ b


  1. 在fb登录时将firebase数据库中的访问令牌保存到
  2. 当应用程序恢复rt,从数据库获取持久化的访问令牌
  3. 检查访问令牌是否仍然有效如果不是,则重新记录用户并获取一个新的访问令牌并将其保存

更新

我注意到我得到这个消息:

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

  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.

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆