28300

Facebook access token nil after app relaunch

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.

Recommend

  • IDX10503: Signature validation failed
  • oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT
  • Syntax error near unexpected token 'elif'
  • read values from form post in jquery or javascript
  • Image map in Flex
  • TFS 2015 - Waiting for an agent to be requested
  • Build Successful but not running on simulator
  • Django model inheritance, filtering models
  • Jquery popup on mouse over of calendar control
  • Check for zero lines output from command over SSH
  • Visual Studio 2010 debugger build correctly - compiler pdb and linker pdb not in synch?
  • Custom Tabgroup Appcelerator
  • Can you perform a UNION without a subquery in SQLAlchemy?
  • PostgreSQL Query without WHERE only ORDER BY and LIMIT doesn't use index
  • How to clear text inside text field when radio button is select
  • How to avoid particles glitching together in an elastic particle collision simulator?
  • Recording logins for password protected directories
  • Splitting given String into two variables - php
  • DirectX11 ClearRenderTargetViewback with transparent buffer?
  • script to move all files from one location to another location
  • Check if a string to interpolate provides expected placeholders
  • Where to put my custom functions in Wordpress?
  • Display Images one by one with next and previous functionality
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • Weird JavaScript statement, what does it mean?
  • Web-crawler for facebook in python
  • Apache 2.4 - remove | delete | uninstall
  • R: gsub and capture
  • jqPlot EnhancedLegendRenderer plugin does not toggle series for Pie charts
  • Comma separated Values
  • PHP: When would you need the self:: keyword?
  • Windows forms listbox.selecteditem displaying “System.Data.DataRowView” instead of actual value
  • Unit Testing MVC Web Application in Visual Studio and Problem with QTAgent
  • SQL merge duplicate rows and join values that are different
  • Benchmarking RAM performance - UWP and C#
  • Acquiring multiple attributes from .xml file in c#
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • reshape alternating columns in less time and using less memory
  • How can I use threading to 'tick' a timer to be accessed by other threads?
  • How to load view controller without button in storyboard?