Facebook listener -> Get event.source

Hi,

I’m currently facing a problem using the Facebook implementation of Corona. Let’s say the user is logged in, everything is set up well. If I :

  • request for “me”
  • request for “me/friends”

I will get my listener (the one I set in my facebook.login( ) function) called twice, but how can I know which of my request is called first (these calls are asynchronous) ? I couldn’t find any event.source-like property to say “This event comes from a me/friends request”, or “this event comes from a me/feed request” ?

Here, a global variable fbCommand is set each time a request is called, and in the listener we check if fbCommand == GET_USER_INFO then … end.
This approach is almost what I’m looking for, despite these requests are asynchronous. This case will not work :

  • request for “me” – fbCommand == GET_USER_INFO
  • request for “me/friends” – fbCommand == GET_USER_FRIENDS now
  • Answer for “me” comes, but we treat it as GET_USER_FRIENDS

If anyone have a workaround for this it would be great :). Thanks !

Jeremy. [import]uid: 188126 topic_id: 32804 reply_id: 332804[/import]

I think the answer is to not fire them off at the same time and maintain a state variable that lets you know which call you’re making.

[code]
local facebook = require “facebook”
local appid = “1234567890”
local request_state=“login”

– listener for “fbconnect” events
local function listener( event )
if ( “session” == event.type ) then
– upon successful login, request list of friends of the signed in user
if ( “login” == event.phase ) then
request_state = “me”
facebook.request( “me” )

– Fetch access token for use in Facebook’s API
local access_token = event.token
print( access_token )
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
if request_state == “me” then
– do your me handling
request_state == “feed”
facebook.request( “me/feed” )
elseif request_state == “feed” then
– do your feed handling
end
elseif ( “dialog” == event.type ) then
print( “dialog”, event.response )
end
end

facebook.login( appId, listener, {“publish_stream”} )
[/code] [import]uid: 19626 topic_id: 32804 reply_id: 130446[/import]

I think the answer is to not fire them off at the same time and maintain a state variable that lets you know which call you’re making.

[code]
local facebook = require “facebook”
local appid = “1234567890”
local request_state=“login”

– listener for “fbconnect” events
local function listener( event )
if ( “session” == event.type ) then
– upon successful login, request list of friends of the signed in user
if ( “login” == event.phase ) then
request_state = “me”
facebook.request( “me” )

– Fetch access token for use in Facebook’s API
local access_token = event.token
print( access_token )
end
elseif ( “request” == event.type ) then
– event.response is a JSON object from the FB server
local response = event.response
if request_state == “me” then
– do your me handling
request_state == “feed”
facebook.request( “me/feed” )
elseif request_state == “feed” then
– do your feed handling
end
elseif ( “dialog” == event.type ) then
print( “dialog”, event.response )
end
end

facebook.login( appId, listener, {“publish_stream”} )
[/code] [import]uid: 19626 topic_id: 32804 reply_id: 130446[/import]

Thanks for your quick answer :).

I’ll rather try to call it sequentially with a FIFO or something, using the state you provided :). [import]uid: 188126 topic_id: 32804 reply_id: 130449[/import]

Thanks for your quick answer :).

I’ll rather try to call it sequentially with a FIFO or something, using the state you provided :). [import]uid: 188126 topic_id: 32804 reply_id: 130449[/import]