Facebook already authorized dialog

Hello community,

I integrated Facebook interaction in my app using Corona’s facebook-library ( require(“facebook”) ).

Everything works fine so far, but something looks exceptional to me:

First time user loggs in and the app is not already autorized to e.g. post messages, the regular authorization dialog from facebook appears, showing all the things my app is going to do with users account.

When I accept it, facebook post is done.

So far so good.

Next time, and every time, my app will post something on the users wall a dialog appears with the message that the user already authorized the app. When I click ok, everything works fine.

So my question: Is this a standard behaviour? Can I avoid this “already authorized” dialog, or do I something wrong? This dialog is very annoying for the user, when he already had accepted my app…

Thank you for your help!

Best regards

   Chris

Hi Chris,

Did you read through this tutorial? It may answer some of your questions.

http://coronalabs.com/blog/2013/07/30/understanding-facebook-authentication/

Take care,

Brent

Hi Brent,

thanks for your quick answer, I’ve seen this tutorial and created the hash, maybe I did something wrong.

Do you think that if so, this could couse my issue?

Here is a screenshot of the dialog I am complaining about, to be sure we’re talking about the same:

http://i.stack.imgur.com/qNZyn.png

Best regards

Can you post your code?  It’s almost like you’re logging in too many times.

Rob

Hey Rob,

here is my code.

The “already authenticated” dialog appears everytime I call e.g. the CheckPageLike() function, that checks if the user

likes a page on facebook.

On login I request the userdata first to get username (not needed here) and then calling the particular action (here the like page).

It seems that the facebook plugin does not buffer the users access token? Do I have to handle it my own? 

But then the user get annoyed everytime he starts the application with the auth-dialog?

Thanks for yout help!

EDIT: Found out that if I do a login() without any permissions before calling any login with a permission, it works.

Maybe corona loads the already existing permissions on the first login?

So is it a possible solution to call the first login without any permissions, and then a second login inside the listener

depending the action I want to do?

-- Facebook Commands local fbCommand -- forward reference local LOGOUT = 1 local POST\_MSG = 2 local CHECK\_LIKE = 3 local fbUserRequest = false local callback = nil local user\_firstname = nil local user\_lastname = nil local user\_name = nil local like\_page\_id = "" local msg\_content = nil local FbHandling = {} ------------------------------------------------------------------------------- -- FUNCTIONS ------------------------------------------------------------------------------- -- -- Facebook listener -- local function listener(event) -- After a successful login event, get user information if ("session" == event.type) then if(event.phase == "login") then -- Request user information fbUserRequest = true facebook.request("me") end elseif("request" == event.type) then local response = event.response if(event.isError) then -- Error else response = json.decode( event.response ) -- If user request, get the data and send command if(fbUserRequest == true) then fbUserRequest = false -- Userdata user\_firstname = response.first\_name user\_lastname = response.last\_name user\_name = response.name if fbCommand == POST\_MSG then facebook.request("me/feed", "POST", {message=replaceWildCards(msg\_content)}) -- posting the message -- Check page like elseif fbCommand == CHECK\_LIKE then facebook.request("me/likes/"..like\_page\_id) -- check if user likes end elseif fbCommand == POST\_MSG then -- Message posted elseif fbCommand == CHECK\_LIKE then -- Check if user likes the page local data = response.data for i=1,#data do local name = data[i].name if data[i].id == like\_page\_id then -- Like if callback then callback(true) end return end end -- Like not if callback then callback(false) end else -- Unknown command response end end elseif("dialog" == event.type) then -- showDialog response end end -- -- Post on users wall: -- function FbHandling:PostMessage(msg) msg\_content = msg fbCommand = POST\_MSG facebook.login(appId, listener, {"publish\_actions"} ) end -- -- Check if user linkes the passed page. -- function FbHandling:CheckPageLike(page\_id, cb) callback = cb like\_page\_id = page\_id fbCommand = CHECK\_LIKE facebook.login(appId, listener, {"user\_likes"}) end -- -- Logout user explicit. -- function FbHandling:Logout(event) fbCommand = LOGOUT facebook.logout() end return FbHandling

Yes, you are supposed to call facebook.login() with no permissions first, then call to request the permissions you need a second time.

Rob

Thank you Rob for your help!

Hi Chris,

Did you read through this tutorial? It may answer some of your questions.

http://coronalabs.com/blog/2013/07/30/understanding-facebook-authentication/

Take care,

Brent

Hi Brent,

thanks for your quick answer, I’ve seen this tutorial and created the hash, maybe I did something wrong.

Do you think that if so, this could couse my issue?

Here is a screenshot of the dialog I am complaining about, to be sure we’re talking about the same:

http://i.stack.imgur.com/qNZyn.png

Best regards

Can you post your code?  It’s almost like you’re logging in too many times.

Rob

Hey Rob,

here is my code.

The “already authenticated” dialog appears everytime I call e.g. the CheckPageLike() function, that checks if the user

likes a page on facebook.

On login I request the userdata first to get username (not needed here) and then calling the particular action (here the like page).

It seems that the facebook plugin does not buffer the users access token? Do I have to handle it my own? 

But then the user get annoyed everytime he starts the application with the auth-dialog?

Thanks for yout help!

EDIT: Found out that if I do a login() without any permissions before calling any login with a permission, it works.

Maybe corona loads the already existing permissions on the first login?

So is it a possible solution to call the first login without any permissions, and then a second login inside the listener

depending the action I want to do?

-- Facebook Commands local fbCommand -- forward reference local LOGOUT = 1 local POST\_MSG = 2 local CHECK\_LIKE = 3 local fbUserRequest = false local callback = nil local user\_firstname = nil local user\_lastname = nil local user\_name = nil local like\_page\_id = "" local msg\_content = nil local FbHandling = {} ------------------------------------------------------------------------------- -- FUNCTIONS ------------------------------------------------------------------------------- -- -- Facebook listener -- local function listener(event) -- After a successful login event, get user information if ("session" == event.type) then if(event.phase == "login") then -- Request user information fbUserRequest = true facebook.request("me") end elseif("request" == event.type) then local response = event.response if(event.isError) then -- Error else response = json.decode( event.response ) -- If user request, get the data and send command if(fbUserRequest == true) then fbUserRequest = false -- Userdata user\_firstname = response.first\_name user\_lastname = response.last\_name user\_name = response.name if fbCommand == POST\_MSG then facebook.request("me/feed", "POST", {message=replaceWildCards(msg\_content)}) -- posting the message -- Check page like elseif fbCommand == CHECK\_LIKE then facebook.request("me/likes/"..like\_page\_id) -- check if user likes end elseif fbCommand == POST\_MSG then -- Message posted elseif fbCommand == CHECK\_LIKE then -- Check if user likes the page local data = response.data for i=1,#data do local name = data[i].name if data[i].id == like\_page\_id then -- Like if callback then callback(true) end return end end -- Like not if callback then callback(false) end else -- Unknown command response end end elseif("dialog" == event.type) then -- showDialog response end end -- -- Post on users wall: -- function FbHandling:PostMessage(msg) msg\_content = msg fbCommand = POST\_MSG facebook.login(appId, listener, {"publish\_actions"} ) end -- -- Check if user linkes the passed page. -- function FbHandling:CheckPageLike(page\_id, cb) callback = cb like\_page\_id = page\_id fbCommand = CHECK\_LIKE facebook.login(appId, listener, {"user\_likes"}) end -- -- Logout user explicit. -- function FbHandling:Logout(event) fbCommand = LOGOUT facebook.logout() end return FbHandling

Yes, you are supposed to call facebook.login() with no permissions first, then call to request the permissions you need a second time.

Rob

Thank you Rob for your help!