facebook.login always navigate to facebook app even though user already logged in

For the previous version of facebook plugin, I was logging in to facebook and granting all the necessary permissions on the first launch of the app. For the next launches, it was handling the login process smoothly without going out of the app. (ios 8)

For this version of facebook plugin, every time I launch the app, it navigates to facebook and asks for an extra confirmation even though I logged in before and I have not logged out. (ios 9)

I have tested with the corona sample facebook app with (ipad 4 ios 8.4.1) and (iphone 5 ios 9.0.2).

Is it a new facebook security issue or something?

For the previous version of facebook plugin, I was logging in to facebook and granting all the necessary permissions on the first launch of the app. For the next launches, it was handling the login process smoothly without going out of the app. (ios 8)

For this version of facebook plugin, every time I launch the app, it navigates to facebook and asks for an extra confirmation even though I logged in before and I have not logged out. (ios 9)

I have tested with the corona sample facebook app with (ipad 4 ios 8.4.1) and (iphone 5 ios 9.0.2).

Is it a new facebook security issue or something?

Check this out.

https://docs.coronalabs.com/plugin/facebook-v4/getCurrentAccessToken.html

Ps. what does your build.setting look like I cannot get facebook to working

Thank you for the response.

However, it seems that facebook.getCurrentAccessToken() does not work in that way. It always returns nil for each launch of the application. It can be tested with the sample facebook codes in the latest public release (2731)

Also you can check that codes for build.settings you are looking for.

For the previous version of facebook plugin, I was logging in to facebook and granting all the necessary permissions on the first launch of the app. For the next launches, it was handling the login process smoothly without going out of the app. (ios 8)

For this version of facebook plugin, every time I launch the app, it navigates to facebook and asks for an extra confirmation even though I logged in before and I have not logged out. (ios 9)

I have tested with the corona sample facebook app with (ipad 4 ios 8.4.1) and (iphone 5 ios 9.0.2).

Is it a new facebook security issue or something?

Check this out.

https://docs.coronalabs.com/plugin/facebook-v4/getCurrentAccessToken.html

Ps. what does your build.setting look like I cannot get facebook to working

Thank you for the response.

However, it seems that facebook.getCurrentAccessToken() does not work in that way. It always returns nil for each launch of the application. It can be tested with the sample facebook codes in the latest public release (2731)

Also you can check that codes for build.settings you are looking for.

@umutdemirell did you ever work this out, I’m just seeing the same thing as I am migrating to v4?

EDIT:

Actually I don’t think it is possible, it’s just a new quirk of the v4 plugin.  So now you must check if you are logged in manually (i.e you have an access token and its not timed out) rather than letting the behind the scenes stuff work it out for you.  Then from that work out if you need to call login or go straight to one of the other requests.

I have this problem as well, 

on android it works great , but seems like on iOS  facebook.getCurrentAccessToken() always returns  nil.

maybe it relates to the new daily builds, or moving to iOS 9.2,  because i don’t remember having this problem in the past.

So you have to call the initial facebook.login() function to get the access token.  Then once it’s logged in facebook.getCurrentAccesstoken() should contain all the values you need to work out if the session is valid.  Migrating to v4 meant I could remove a lot of the code from the old plugin that was saving all this data manually.  Like it!

Hi, piling on here - I seem to get the same problem:

Every relaunch of the app, on running facebook.login for a previosuly logged in user it quickly switches to Facebook to relogin with v4. With the old version, this login check could be done without app switching, which was just smoother - the facebook.login just ran in the backgorund of my code and smoothly updated. The jump between apps is quite jarring.

I figure the only way to get around this would be to locally save the access taken in a database, which to me doesn’t seem perfectly secure, and either way - if we want to use it to interact with Facebook, we need to do the “app switch login dance” again anyway?

I think this is quite an annoying issue, just wanted to bump and see if anyone has figured out any solution for this or has any suggestions?

To add more insult to injury: if we do this without an internet connection, the app just switches to facebook and lags out, instead of going back to my app. So if a user starts the app on an airplane for example they get booted out from the app pretty much. Before, since this was handled in the app, we could have much more graceful failing.

Is this really the expected behaviour?

You should be able to check to see if you have a token after calling .init() and not have to call .login() which causes the fast switch. See:

https://docs.coronalabs.com/plugin/facebook-v4/getCurrentAccessToken.html

There is code at the bottom to demonstrate this.

Rob

Thanks for your answer!

However, I’m not sure if I follow - there is no .init() function for Facebook (I’ve double checked by printing the entire “facebook” array, and I see no such function?

So calling it just gives me a runtime error.

And calling facebook.getCurrentAccessToken() just gives me a “nil”; in other words, I don’t have the token

Just to make sure we are talking about the same thing, I don’t mean resuming an app from having it suspended - but from force closing it. To re-state the problem more clearly:

 

  1. A user starts the app, and logs in to Facebook.

 

1.1. Upon this, I save a boolean in a local database like UserIsLoggedIn = true - to save the fact that the user was logged in. If we don’t, the user would have to manually relogin every time the app was force closed.

 

  1. User force quits the app (or updates it, or does any action that does a complete exit and relaunch of the app)

 

  1. User relaunches the app

 

  1. The app checks the database and if UserIsLoggedIn was true, then we quickly run facebook.login to relogin.

 

4.1a. Before, the facebook.login ran inside the app, so I just showed a quick “loading” indicator for a second, and the user was logged back in. Perfect!

 

4.1b. Now, facebook.login instead does an app switch, which is very unreliable and jarring for the user when it relaunches the app. This feels like unexpected behaviour. If i instead just run getCurrentAccessToken(), it just gives me a nil value.

It worked perfectly like it was before. Maybe I’m missing something, I can’t quite figure out what the expected solution to this is, with the new v4 of the plugin. 

My mistake on the .init() call.

Have you looked at the Sample app that we ship with Corona SDK for Facebook?

Hi guys,
I whould like to share my work around for this problem -
I notice on ios that while the getAccessToken during the application init returned nil, it return me token few seconds afterwards if the user click on the login button.

So now during the init of the application i try to getAccessToken 3 times with 1 second delay between each call, usually it returns good token on the second attempt.

Hope it can help you also

Yes, I have now tried exactly the Facebook sampe code (with my Facebook app id, and another app Id of a live FB app with many thousands of actual users), and the exact same thing happens :frowning:

HOWEVER - using barak.eliau’s suggestion I actualy got it to work; I experimented and ran the code withing a timer with just 10 milliseconds delay in different iterations, and that gives me a table with the token pretty quickly :slight_smile:

This maybe needs to be reflected in the documentation, that the function needs to be delayed.

Either way,I made a quick code snippet to test this, if it helps people to play around:

local testtime = 10 local curtime = testtime local testTimer = timer.performWithDelay(testtime,function() print("Trying Facebook after time:", curtime) local accessToken = facebook.getCurrentAccessToken() if facebook.isActive == true and accessToken then print("Got access token!") else print("Facebook not active :(") end curtime = curtime + testtime end,10)

I will experiment a bit more, but for now that seems like the solution :slight_smile:

Good find.  Having to run the same delay loop myself.

Is this not locally stored so theoretically access could be quicker?

I have the same issue. Adding a timer doesn´t look like the optional solution specially when this was supported in the previous version. For now I wont migrate fully to facebook v4. But facebook already sent me a message:

 has been making recent API calls to Graph API v2.0, which will reach the end of the 2-year deprecation window on Monday, August 8, 2016. Please migrate all calls to v2.1 or higher in order to avoid potential broken experiences.

I hope we can have a fix for this “issue” before August

@umutdemirell did you ever work this out, I’m just seeing the same thing as I am migrating to v4?

EDIT:

Actually I don’t think it is possible, it’s just a new quirk of the v4 plugin.  So now you must check if you are logged in manually (i.e you have an access token and its not timed out) rather than letting the behind the scenes stuff work it out for you.  Then from that work out if you need to call login or go straight to one of the other requests.

I have this problem as well, 

on android it works great , but seems like on iOS  facebook.getCurrentAccessToken() always returns  nil.

maybe it relates to the new daily builds, or moving to iOS 9.2,  because i don’t remember having this problem in the past.

So you have to call the initial facebook.login() function to get the access token.  Then once it’s logged in facebook.getCurrentAccesstoken() should contain all the values you need to work out if the session is valid.  Migrating to v4 meant I could remove a lot of the code from the old plugin that was saving all this data manually.  Like it!