Energy Request LIke in Candy Crush in Corona

Hello Guys :slight_smile: Im new  to this forum and a new Game developer using Corona SDK so bear with my noobness. Thank you :slight_smile:

I just want to know how the Energy Request in Facebook work, like we see in Candy Crush, and other games that uses Energy/Battery.

Your Help will be greatly appreciated and I will  acknowledged you in our Thesis

Thanks

Jam

Up, Really need help guys :frowning:

where do I start? do I have to study Facebook SDK? or their graph API’s?

Hi @leviosa09.  Did you ask this same question on twitter? 

Basically Facebook is an insanely big product.  While we strive to make sure that Corona SDK apps can talk to Facebook and use features available through their REST based API, there are parts of Facebook that are beyond the scope of what we can really provide support for.  So yes, you need to study the Facebook SDK/Graph APIs.    You can look at our documentation on our face book.* API calls (see: http://docs.coronalabs.com/api/library/facebook/index.html)

This question was asked on Twitter earlier this week and when I looked into it, it appears you would use a facebook.showDialog(“apprequest”) call to ask your friends to help you.  However, once one that notification has happened and a friend wants to give you energy, they can’t talk to your app directly.  It seems to me you’re going to need some web server backend process to collect the things gifted to you and then have your app fetch that data when it needs it. 

See:  https://developers.facebook.com/docs/concepts/requests/

Once you figure this out, I’m sure the community would love for you to report back and say how you did it.  Perhaps it would be a good guest blog post.

Up, Really need help guys :frowning:

where do I start? do I have to study Facebook SDK? or their graph API’s?

Hi @leviosa09.  Did you ask this same question on twitter? 

Basically Facebook is an insanely big product.  While we strive to make sure that Corona SDK apps can talk to Facebook and use features available through their REST based API, there are parts of Facebook that are beyond the scope of what we can really provide support for.  So yes, you need to study the Facebook SDK/Graph APIs.    You can look at our documentation on our face book.* API calls (see: http://docs.coronalabs.com/api/library/facebook/index.html)

This question was asked on Twitter earlier this week and when I looked into it, it appears you would use a facebook.showDialog(“apprequest”) call to ask your friends to help you.  However, once one that notification has happened and a friend wants to give you energy, they can’t talk to your app directly.  It seems to me you’re going to need some web server backend process to collect the things gifted to you and then have your app fetch that data when it needs it. 

See:  https://developers.facebook.com/docs/concepts/requests/

Once you figure this out, I’m sure the community would love for you to report back and say how you did it.  Perhaps it would be a good guest blog post.

I’ve just finished to test this on the latest public release, try this code

build.settings

settings = { orientation = { default = "portrait", content = "portrait", supported = { "portrait" } }, iphone = { plist = { UIApplicationExitsOnSuspend = false, FacebookAppID = "XXXXXXXXXX", -- replace XXXXXXXXXX with your facebook appId CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXX", -- replace XXXXXXXXXX with your facebook appId } } } } } }

main.lua

-- Classes local facebook = require("facebook"); -- Constants and variables local \_W = display.contentWidth; local \_H = display.contentHeight; local \_CX = \_W\*0.5; local \_CY = \_H\*0.5; -- Configuration io.output():setvbuf('no'); display.setStatusBar( display.HiddenStatusBar ); local background = display.newRect(0,0,\_W,\_H); background:setFillColor(10,70,200); background:setReferencePoint(display.CenterReferencePoint); background.x = \_CX; background.y = \_CY; local description = display.newText("touch to open fb dialog", 0,0,native.systemfont,\_W\*0.075); description:setReferencePoint(display.CenterReferencePoint); description.x = \_CX; description.y = \_CY; local function touchHandler(event) if event and event.phase == "ended" then -- listener for "fbconnect" events local function listener( event ) if ( "session" == event.type ) then -- upon successful login, request list of friends if ( "login" == event.phase ) then local function onComplete(event) print("calling on complete with event = "..tostring(event)); for k,v in pairs(event) do print("event k="..tostring(k).." v="..tostring(v)); end end facebook.showDialog( "apprequests", { message="You should download this game!" }, onComplete ); end elseif ( "dialog" == event.type ) then print( event.response ) end end -- first argument is the app id that you get from Facebook facebook.login( "XXXXXXXXXX", listener ) --replace XXXXXXXXXX with your Facebook App ID end end background:addEventListener("touch", touchHandler);

As you can see your friends will receive the request but nothing returns to the showDialog callback.
In my case I need how many friends are selected and if possible the request id, maybe also friends ids to track request and give something to the player like an extra life in Candy Crush

I’ve just finished to test this on the latest public release, try this code

build.settings

settings = { orientation = { default = "portrait", content = "portrait", supported = { "portrait" } }, iphone = { plist = { UIApplicationExitsOnSuspend = false, FacebookAppID = "XXXXXXXXXX", -- replace XXXXXXXXXX with your facebook appId CFBundleURLTypes = { { CFBundleURLSchemes = { "fbXXXXXXXXXX", -- replace XXXXXXXXXX with your facebook appId } } } } } }

main.lua

-- Classes local facebook = require("facebook"); -- Constants and variables local \_W = display.contentWidth; local \_H = display.contentHeight; local \_CX = \_W\*0.5; local \_CY = \_H\*0.5; -- Configuration io.output():setvbuf('no'); display.setStatusBar( display.HiddenStatusBar ); local background = display.newRect(0,0,\_W,\_H); background:setFillColor(10,70,200); background:setReferencePoint(display.CenterReferencePoint); background.x = \_CX; background.y = \_CY; local description = display.newText("touch to open fb dialog", 0,0,native.systemfont,\_W\*0.075); description:setReferencePoint(display.CenterReferencePoint); description.x = \_CX; description.y = \_CY; local function touchHandler(event) if event and event.phase == "ended" then -- listener for "fbconnect" events local function listener( event ) if ( "session" == event.type ) then -- upon successful login, request list of friends if ( "login" == event.phase ) then local function onComplete(event) print("calling on complete with event = "..tostring(event)); for k,v in pairs(event) do print("event k="..tostring(k).." v="..tostring(v)); end end facebook.showDialog( "apprequests", { message="You should download this game!" }, onComplete ); end elseif ( "dialog" == event.type ) then print( event.response ) end end -- first argument is the app id that you get from Facebook facebook.login( "XXXXXXXXXX", listener ) --replace XXXXXXXXXX with your Facebook App ID end end background:addEventListener("touch", touchHandler);

As you can see your friends will receive the request but nothing returns to the showDialog callback.
In my case I need how many friends are selected and if possible the request id, maybe also friends ids to track request and give something to the player like an extra life in Candy Crush