facebook.request( "me/scores", "POST", {score = 1} ) - cant get to work

I can get scores from facebook but cannot submit scores?
Why wont this work?

local FBlistener

local FBappId = “myActualAppID”

local function FBonClick( event )
if(event.phase == “release”) then
facebook.login( FBappId, FBlistener, {“publish_actions”} )
end
end

function FBlistener( event )
if ( “session” == event.type ) then
if ( “login” == event.phase ) then
facebook.request( “me/scores”, “POST”, {score = 1} ) --score set to 1 just to test
end
elseif ( “request” == event.type ) then

if ( event.isError ) then
local response = event.response

local errorText = display.newText(response, 0, 0, font1, 20 )
errorText:setTextColor(7, 52, 63)
errorText.x = display.contentWidth / 2
errorText.y = 25
GUI:insert(errorText)

print(response)

end
end

end

local FBbutton = ui.newButton {
defaultSrc = “fb.png” , defaultX = “300” , defaultY = “50”,
onEvent = FBonClick,
id = “FBbutton”
}

FBbutton.x = display.contentWidth / 2
FBbutton.y = display.screenOriginY + buttonsYmove + buttonsYdif*3 -10
GUI:insert(FBbutton) [import]uid: 20289 topic_id: 30164 reply_id: 330164[/import]

Hi Mush, the following line is wrong:
[lua] facebook.request( “me/scores”, “POST”, {score = 1} )[/lua]

You can’t update scores using “me/scores”. Instead of me, use user ID. (e.g.: “123456789/scores”)

I’m requesting user ID with this code:
[lua]facebook.request(“me”, “GET”, {fields=“id”}, onGetResult)

function onGetResult(event)
local userId = event.response.id
end[/lua]

Note that to get the user ID you need to use User Token and to post scores you need to use App Token (https://developers.facebook.com/docs/opengraph/using-app-tokens/) [import]uid: 65163 topic_id: 30164 reply_id: 120792[/import]

Thank you very much Diego - you are a champion.

I ended up having to use :

facebook.request( fbCurrentUserID … “/scores?score=” … score, “POST”)

but your reply gave me a massive push in the right direction.

If you have to post multiple parameters - how would you do it.

Like if you had to post access_token, userid how would the format be after the “POST” section. [import]uid: 20289 topic_id: 30164 reply_id: 120842[/import]

I guess you can include the access_token field in your “url” by separating parameters with “&” character.

e.g.

facebook.request( fbCurrentUserID … “/scores?score=” … score&access_token=…, “POST”)

You can see more examples of facebook api here: https://developers.facebook.com/docs/reference/api/

Look for "Event Names: https://graph.facebook.com/search?fields=name&q=conference&type=event " as a simple example.
[import]uid: 65163 topic_id: 30164 reply_id: 120857[/import]

Hi Mush, the following line is wrong:
[lua] facebook.request( “me/scores”, “POST”, {score = 1} )[/lua]

You can’t update scores using “me/scores”. Instead of me, use user ID. (e.g.: “123456789/scores”)

I’m requesting user ID with this code:
[lua]facebook.request(“me”, “GET”, {fields=“id”}, onGetResult)

function onGetResult(event)
local userId = event.response.id
end[/lua]

Note that to get the user ID you need to use User Token and to post scores you need to use App Token (https://developers.facebook.com/docs/opengraph/using-app-tokens/) [import]uid: 65163 topic_id: 30164 reply_id: 120792[/import]

Thank you very much Diego - you are a champion.

I ended up having to use :

facebook.request( fbCurrentUserID … “/scores?score=” … score, “POST”)

but your reply gave me a massive push in the right direction.

If you have to post multiple parameters - how would you do it.

Like if you had to post access_token, userid how would the format be after the “POST” section. [import]uid: 20289 topic_id: 30164 reply_id: 120842[/import]

I guess you can include the access_token field in your “url” by separating parameters with “&” character.

e.g.

facebook.request( fbCurrentUserID … “/scores?score=” … score&access_token=…, “POST”)

You can see more examples of facebook api here: https://developers.facebook.com/docs/reference/api/

Look for "Event Names: https://graph.facebook.com/search?fields=name&q=conference&type=event " as a simple example.
[import]uid: 65163 topic_id: 30164 reply_id: 120857[/import]

Hi Mush, how did you get the GET scores to work? I can get the POST to work but not the GET. I’d like to get all the scores of my app. This is my code so far…

local params = {} params.body = "&access\_token="..access\_token network.request( "https://graph.facebook.com/v2.1/fbappid/scores", "GET", networkListener, params)

Thank you very much. Oh and one more thing, whenever you make a facebook.request execution, do you need to login facebook first? Do you need to attach access_token everytime you do facebook.request even if it’s already been logged in? Thank you.

Hi Mush, how did you get the GET scores to work? I can get the POST to work but not the GET. I’d like to get all the scores of my app. This is my code so far…

local params = {} params.body = "&access\_token="..access\_token network.request( "https://graph.facebook.com/v2.1/fbappid/scores", "GET", networkListener, params)

Thank you very much. Oh and one more thing, whenever you make a facebook.request execution, do you need to login facebook first? Do you need to attach access_token everytime you do facebook.request even if it’s already been logged in? Thank you.