facebook.login() and facebook.request() second time

Hi, me again with facebook issue :smiley:

My facebook app works great, but when I open this built app again (for second or third time), every time I experience some errors.

So, I use this code for login and for name and link request:

local function listener( event ) if ( "session" == event.type ) then if ( "login" == event.phase ) then facebook.request( "me" ) end elseif ( "request" == event.type ) then if (event.isError) then local alert = native.showAlert( "...", "...", { "OK" }) end if (not event.isError) then local response = json.decode(event.response) fullName = response.name link = response.link end end end facebook.login( "XXXXXXXXXX", listener, {"publish\_stream"} )

In other function I have some text objects that show response name and response link.

When I run this app for a first time, everything works well and I get name and link without any problems.

If I try to run this app for a second time, I get nothing. I tried to fix this using facebook.logout() after getting response name and response link but without any success.

I need to get new response every time user start this app, not just for a first time.

Please, I need some ideas about it. Thanks.

Are you getting errors in your console log?  If you don’t know how to get your console log, please read this post: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Put some print statements in your listener function to make sure it’s getting triggered and does what it supposed to do.

It’s really hard to help you when we have to guess at what’s going on.

Also what version of Corona are you using?  What device are you building for?  What OS version is running on that device?  Are you killing and restarting the app, or are you just switching to an already running version?   Remember you can leave your app, and tap the icon and it does not re-start your app, it just switches to what was already in memory.

I’ll check these things.

Is it allowed to make facebook.login() everytime user starts the app?

Yes, in fact you need to login every time because the login tokens don’t last forever.   Once your app has permissions, they won’t be interrupted by the login process again, just a quick flicker of the facebook app opening and closing quickly to verify the login.

Hi Rob,

So you are saying when you exit the app you should log the user out so they have to login again each time they launch the app? Or just call the login and if the user is still saved it will keep them in without entering it again? I noticed the user did not need to login each time but after some amount of time the app would not post or do anything. That was a few months ago and maybe the newer builds has it where this does not happen.

Warren

I don’t know how important it is to log them out.  You do have to log them in each time.  You should not have to interact with a facebook dialog after the first time unless your app wants new permissions.

Are you getting errors in your console log?  If you don’t know how to get your console log, please read this post: http://www.coronalabs.com/blog/2013/07/09/tutorial-basic-debugging/

Put some print statements in your listener function to make sure it’s getting triggered and does what it supposed to do.

It’s really hard to help you when we have to guess at what’s going on.

Also what version of Corona are you using?  What device are you building for?  What OS version is running on that device?  Are you killing and restarting the app, or are you just switching to an already running version?   Remember you can leave your app, and tap the icon and it does not re-start your app, it just switches to what was already in memory.

I’ll check these things.

Is it allowed to make facebook.login() everytime user starts the app?

Yes, in fact you need to login every time because the login tokens don’t last forever.   Once your app has permissions, they won’t be interrupted by the login process again, just a quick flicker of the facebook app opening and closing quickly to verify the login.

Hi Rob,

So you are saying when you exit the app you should log the user out so they have to login again each time they launch the app? Or just call the login and if the user is still saved it will keep them in without entering it again? I noticed the user did not need to login each time but after some amount of time the app would not post or do anything. That was a few months ago and maybe the newer builds has it where this does not happen.

Warren

I don’t know how important it is to log them out.  You do have to log them in each time.  You should not have to interact with a facebook dialog after the first time unless your app wants new permissions.