Hi,
Can someone point me the direction into inviting friends (who is not using the apps) from Facebook and once the friend downloaded the apps, the user is rewarded with some point systems?
Thank you.
Hi,
Can someone point me the direction into inviting friends (who is not using the apps) from Facebook and once the friend downloaded the apps, the user is rewarded with some point systems?
Thank you.
Hi there,
At a high level, the way to do this is:
Use the Request Dialog to allow your user to invite friends (see http://docs.coronalabs.com/api/library/facebook/showDialog.html and https://developers.facebook.com/docs/reference/dialogs/requests/)
Parse the response from the dialog into the list of Facebook IDs that your user actually invited, and story it in a file
Issue GET requests (http://docs.coronalabs.com/api/library/facebook/request.html) to me/friends asking for the ‘installed’ field to see which of your user’s friends have installed your app
Compare the friends who installed your app to the list of friends your user invited to determine when to reward your user
Andrew
Hi Andrew,
Thanks for pointing me the direction!
I’m currently in the midst of getting the response from the request dialog to get the array of facebook id that the user has invited but I am facing some difficulty that I hope you can give me the extra help.
I look at the response data that is been returned from https://developers.facebook.com/docs/reference/dialogs/requests/ documentation and it states that it will return request and to.
So what I did is calling the dialog using
facebook.showDialog("apprequests", { app\_id = fbAppID} )
after which I get the callback in the listener with the following
if ( "dialog" == event.type ) then inviteText.text = "Friend invited" print( "dialog", event.response ) local data = json.decode(event.response) for i = 1, #data.to do inviteText.text = inviteText.text .. ", " .. data.to[i].user\_id end end
to put them in string so that I can cross check the array list. However, it is returning nothing.
Did I use the wrong attribute?
Thanks in advanced!
Unfortunately the response from the dialog is not a JSON table, it’s an fbconnect URL. Your statement print(“dialog”, event.response) should print something like fbconnect://success?to[1]=12345. Is that what you see? You then have to parse that string to extract the facebook IDs.
I just checked the response from the print statement. It is returning nothing. Did I call it wrongly?
You should probably put a ‘message’ field in your parameters to facebook.showDialog. Without that, it’s possible the request may not be sent at all, which would explain why your print is blank.
Hi Andrew,
I tried putting in the message and printing the event out however it is still nil. The code is as follows:
local function facebookListener( event ) if ( "session" == event.type ) then -- upon successful login, request list of friends of the signed in user if ( "login" == event.phase ) then inviteText.text = "Pulling friend list..." local params = { app\_id = fbAppID, message = "Try this! Test 123" } facebook.showDialog("apprequests", params) 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 elseif ( "dialog" == event.type ) then print ( "event type:" , event.type) print( "event name:" , event.name) print ( "event data:", event.data) print( "event response: ", event.response) end end
I am able to pull out the request dialog with my list of friends and invited one of my friends and he indeed received the request as well. However at the print area, I’m getting
I/Corona (31434): event type: dialog I/Corona (31434): event name: fbconnect I/Corona (31434): event data: nil I/Corona (31434): event response:
Is it because that my friend has already been invited previously which is why it is returning nothing? But there isn’t fbconnect://success in the response as well.
Try also printing event.didComplete and event.isError and see what they say.
It should be fine if you had previously sent an invite to that friend – you can keep sending requests to the same person without a problem.
I’m getting
I/Corona ( 811): event type: dialog I/Corona ( 811): event name: fbconnect I/Corona ( 811): event data: nil I/Corona ( 811): event response: I/Corona ( 811): event complete: true I/Corona ( 811): event error: false
Seems like there is no error.
OK. Well, I don’t see anything that’s obviously wrong with your code. Can you post your build.settings? It’s possible your facebook setup there isn’t correct. Can you also post your code where you call facebook.login()? I doubt either is the problem, but it doesn’t hurt to check.
What device are you using? Are you on an Android or iOS device, and which version? What version of Corona are you using?
Hi Andrew,
I have got it working which like what you have pointed out, it is the version issue of Corona where I did a search and found you guys talking about build 1154 and previous wasn’t working. I had mine at build 1137 and now using build 1202 and it is working like a champ now.
Thanks for your help!
Yup, that’s exactly right. Glad you got it working.
Hi there,
At a high level, the way to do this is:
Use the Request Dialog to allow your user to invite friends (see http://docs.coronalabs.com/api/library/facebook/showDialog.html and https://developers.facebook.com/docs/reference/dialogs/requests/)
Parse the response from the dialog into the list of Facebook IDs that your user actually invited, and story it in a file
Issue GET requests (http://docs.coronalabs.com/api/library/facebook/request.html) to me/friends asking for the ‘installed’ field to see which of your user’s friends have installed your app
Compare the friends who installed your app to the list of friends your user invited to determine when to reward your user
Andrew
Hi Andrew,
Thanks for pointing me the direction!
I’m currently in the midst of getting the response from the request dialog to get the array of facebook id that the user has invited but I am facing some difficulty that I hope you can give me the extra help.
I look at the response data that is been returned from https://developers.facebook.com/docs/reference/dialogs/requests/ documentation and it states that it will return request and to.
So what I did is calling the dialog using
facebook.showDialog("apprequests", { app\_id = fbAppID} )
after which I get the callback in the listener with the following
if ( "dialog" == event.type ) then inviteText.text = "Friend invited" print( "dialog", event.response ) local data = json.decode(event.response) for i = 1, #data.to do inviteText.text = inviteText.text .. ", " .. data.to[i].user\_id end end
to put them in string so that I can cross check the array list. However, it is returning nothing.
Did I use the wrong attribute?
Thanks in advanced!
Unfortunately the response from the dialog is not a JSON table, it’s an fbconnect URL. Your statement print(“dialog”, event.response) should print something like fbconnect://success?to[1]=12345. Is that what you see? You then have to parse that string to extract the facebook IDs.
I just checked the response from the print statement. It is returning nothing. Did I call it wrongly?
You should probably put a ‘message’ field in your parameters to facebook.showDialog. Without that, it’s possible the request may not be sent at all, which would explain why your print is blank.
Hi Andrew,
I tried putting in the message and printing the event out however it is still nil. The code is as follows:
local function facebookListener( event ) if ( "session" == event.type ) then -- upon successful login, request list of friends of the signed in user if ( "login" == event.phase ) then inviteText.text = "Pulling friend list..." local params = { app\_id = fbAppID, message = "Try this! Test 123" } facebook.showDialog("apprequests", params) 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 elseif ( "dialog" == event.type ) then print ( "event type:" , event.type) print( "event name:" , event.name) print ( "event data:", event.data) print( "event response: ", event.response) end end
I am able to pull out the request dialog with my list of friends and invited one of my friends and he indeed received the request as well. However at the print area, I’m getting
I/Corona (31434): event type: dialog I/Corona (31434): event name: fbconnect I/Corona (31434): event data: nil I/Corona (31434): event response:
Is it because that my friend has already been invited previously which is why it is returning nothing? But there isn’t fbconnect://success in the response as well.
Try also printing event.didComplete and event.isError and see what they say.
It should be fine if you had previously sent an invite to that friend – you can keep sending requests to the same person without a problem.
I’m getting
I/Corona ( 811): event type: dialog I/Corona ( 811): event name: fbconnect I/Corona ( 811): event data: nil I/Corona ( 811): event response: I/Corona ( 811): event complete: true I/Corona ( 811): event error: false
Seems like there is no error.