Ok, I got in it again ! And it seems to works, although it needs some tweak. I won’t be able to post all the code, since mine is kinda heavy (lot of stuff going on, not related to this problem). So this is what I had before :
A “Facebook Connect button”, calling this function :
function triggerFacebookLogin(event) facebook.login(fbAppID, facebookListener) end facebookLoginButton:addEventListener("touch", triggerFacebookLogin)
A “Share Button”, calling this function :
function triggerFacebookShare(event) fbCommand = POST\_PHOTO facebook.login(fbAppID, facebookListener) end facebookShareButton:addEventListener("touch", triggerFacebookShare)
The facebookListener is basically what we already have in the Corona’s Facebook Sample “Scrumptious”.
So far, here’s what a user had to do in order to post on Facebook, for the first time :
- The user launches the Corona App.
- He has to touch the “Facebook Connect Button” : the app swapps to Facebook, then it asks him to authorize his Facebook App to retrieve his login informations.
- Once the user accepts, it switches back to the Corona app, then he has to touch the “Share Button”. It swapps again to the Facebook App so that the user authorizes to publish things on his wall.
- Once the user accepts (again), it switches back to the Corona App. Then, he needs to touch (again) the “Share Button” so that the picture gets posted.
If the user has already posted at least one picture (and had to go through all those steps), if he wants to post an other picture, he has to :
- Launch the Corona App.
- The user touches the “Facebook Connect Button” : it swapps to the Facebook App then automatically goes back to the Corona Back (since the user is already logged)
- He touches the “Share Button” : the pictures gets posted.
So, as you can see, if the user does it for the first time, he has to go through the “double identification process”, which is really annoying, but mendatory. Later, I actually managed to simplify the process by having one single button : the function called simply changes once he logins to Facebook, which is a lot simplier for the user.
But, if the users do it a second time, he still has to go through the “Facebook Connect Login” process, which is useless since he has already done that.
And this is where I was a few months ago when I asked : " Is there any way to know if a user already logged to Facebook".
Well, the short answer is : yes, there is. And it’s quite simple actually.
I tried what Brent suggested but the problem was it automatically swapped to the Facebook App everytime the user launches the Corona App (tell me if I’m wrong, but it seems everytime it calls facebook.login, the app swapping is necessary).
So, the Facebook Listener returns an expiration event. Which is simply a timecode (just like os.time), corresponding to the lifetime duration of the Facebook login token. By the way, the duration is now set to 60 days.
Once the user successfully logins, the expiration event is saved in his savegame. Everytime he launches the app, it first verify the expiration date is still OK, or not. If it’s not, then the user has to go through the login process again.
I’ve still got to find out what happens if the users removes the Facebook App from his profile, and how to deal with it. But it seems to work ! And, i’m also wondering if the event.expiration depends on “Facebook local time” or “User device time” which could be a problem, since users do seem to change their “user device time” because of some games like Candy Crush…
If you see any other way or if I’m totally wrong, don’t hesitate to tell me !