multiple facebook requests one after the other ?!?

Ng Chun Chong: sorry, I just read your code again.

It will work fine, but it does not allow you to run multiple requests at the same time.

What we were trying to achieve is sending:

facebook.request("id")  facebook.request(appid.."/scores")  

at the same time and be able to handle the responses properly.

What you did here is wait for the first response to come back and then send another one. There’s no issues with this approach.

This is my working solution for batch facebook requests :slight_smile:
local requestcount=0
local function listener(event)

if (“session”==event.type) then

if event.phase~=“login” then

return

else

local attachment={

name="",

link="",

caption="",

description="",

picture="",

actions=json.encode({{ name="",link=""}})

}

facebook.request(“me/feed”,“POST”,attachment)

facebook.request(“me”)

end

elseif (“request”==event.type) then

response=json.decode(event.response)

if requestcount==0 then

requestcount=requestcount+1

name=response.name

id=response.id

local function networkListener(event)

if (event.isError) then

else

end

end

network.download(“https://graph.facebook/”…id…"/picture",“GET”,networkListener,id…".jpg",system.DocumentsDirectory)

– appid is you application id

facebook.request(appid…"/scores")

elseif requestcount==1 then

data=response.data

end

end

end

end

Ng Chung Chong: your solution will only work for requests sent after response to the previous one is received.

If you try to send them all at once, this may fail [depends on how facebook responds to them].

Krystian

Hi Krystian, just finished testing on my latest app for a week and no error so far.

Ng Chun Chong: sorry, I just read your code again.

It will work fine, but it does not allow you to run multiple requests at the same time.

What we were trying to achieve is sending:

facebook.request("id")  facebook.request(appid.."/scores")  

at the same time and be able to handle the responses properly.

What you did here is wait for the first response to come back and then send another one. There’s no issues with this approach.

Does anybody have any other suggestions to this issue? All the solutions above are really workarounds and difficult to get working well.

What I am trying to do is

  1. login to get my latest score

  2. Update the score if the latest score is higher than facebook score

  3. Get facebook friend scores

@ahmadooka:

well what you are trying to achieve is pretty simple as it’s never more then one simultaneous request:

  1. Login

  2. In Login handler, detect that login was successful, ask for your latest score and set a flag to indicate this is what you have done

  3. Wait for another response, check that your flag was set to ‘get my latest score’, check if in response your score was lower than your current highscore and update it if needs be by setting another flag. If not, set a different one and get the score.

Well… everything is simply achievable by a state flag.

You can also use one of the AK libraries from code exchange, where you can run a request and pass a listener.

Just remember not to run multiple requests at once, wait for one to come back and then submit the next one.

You can get this in one request. As facebook.request() argument you can pass:

facebook.request("me?fields=id,name,friends,address,email,age\_range")

Argumets are based on facebok graph api requests and you can combine them. Remember that now some fields require permissions (friends). As referenve please use this tool provied by facebook: https://developers.facebook.com/tools/explorer

Thank you both.

@krystian6

I can pass listeners per request? That sounds interesting. Where exactly can I get this library?

Does anybody have any other suggestions to this issue? All the solutions above are really workarounds and difficult to get working well.

What I am trying to do is

  1. login to get my latest score

  2. Update the score if the latest score is higher than facebook score

  3. Get facebook friend scores

@ahmadooka:

well what you are trying to achieve is pretty simple as it’s never more then one simultaneous request:

  1. Login

  2. In Login handler, detect that login was successful, ask for your latest score and set a flag to indicate this is what you have done

  3. Wait for another response, check that your flag was set to ‘get my latest score’, check if in response your score was lower than your current highscore and update it if needs be by setting another flag. If not, set a different one and get the score.

Well… everything is simply achievable by a state flag.

You can also use one of the AK libraries from code exchange, where you can run a request and pass a listener.

Just remember not to run multiple requests at once, wait for one to come back and then submit the next one.

You can get this in one request. As facebook.request() argument you can pass:

facebook.request("me?fields=id,name,friends,address,email,age\_range")

Argumets are based on facebok graph api requests and you can combine them. Remember that now some fields require permissions (friends). As referenve please use this tool provied by facebook: https://developers.facebook.com/tools/explorer

Thank you both.

@krystian6

I can pass listeners per request? That sounds interesting. Where exactly can I get this library?