Using Facebook API (DEF-1743)

I’m stuck, trying to use the Facebook API. I have successfully managed to get a token(verified on Facebook), and now I’m stuck, trying to access my token and user-data. I’ve been trying to see if I can find an answer in the API reference, but I don’t know where I fail. Could someone please just guide me in the right direction for how I use the API to get data?

My obvious attempts (that off course don’t work, for some reason):

...
local fb_me = facebook.me -- this results in DEBUG:SCRIPT: function: 0x147f6de10
...

...
local fb_me = facebook.me() -- This results in DEBUG:SCRIPT: nil
...

What am I doing wrong?

1 Like

Same problem, how i can use facebook api to save high score with Defold

1 Like

Stupid question but did you check the manual? Pay special attention to the last paragraph, “Caveats”, regarding the devapp etc. It’s also important to obtain the correct facebook permissions when interacting with that service.

3 Likes

Regarding high score, you should be able to do that by manually constructing http requests outside of our facebook api (which is quite barebone). Read more in the facebook docs.

4 Likes

As Ragnar said, the API is bare bones, but with facebook.access_token() you have full access to the entire Facebook Graph API using plain http.request() calls. Remember to request additional permission if needed!

Note: If you want to test the Graph API on a local build you can get an access token from the Facebook Graph API explorer

2 Likes

You guys rock. :tada: It was off course me, that misinterpreted what the caveats said. How that is possible, is beyond me, since the manual is loud and clear. :blush: It work flawlessly now, when I debug through my bundled app, so I should be able to move along on my own from here. At least for the moment. Thank you so much, @Ragnar_Svensson .

4 Likes

Happy to hear it works! When working with facebook interaction, make sure to use hot-reload all the time with the scripts and the on_reload function. It makes everything so much easier and even quite fun. :slight_smile:

4 Likes

Thank you, i success to use http.requet to get high score from Facebook Graph API. But i have a problem, when first time i request score, its successfully but in second time I request, its error
FATAL:DLIB: ETag mismatch ("981ebe231dbb462cec0347f71aaafc757ac4ce38" vs ) ERROR:SCRIPT: HTTP request to 'https://graph.facebook.com/v2.5/me/scores?access_token=CAAIZAM7tgTYgBAFXUxoUZBfAnGOsRu55O4QgsrLNhY8GUDYR9CIZBlHIcOQcqMjs1aZCuD34N4ZAZCpvT2w907UWCM5h5wB7GsPOX52ZAURDyB2BlU25tD5k0JlNZBwGQbggkLc4kr7eJ61cR1sgJ2btXsMOoO21sPlszpgb5MZCwXevlrXXseTgeNRFZAwYuKXy4ZD' failed (http result: -8 socket result: 0) DEBUG:SCRIPT: 0 DEBUG:SCRIPT: DEBUG:SCRIPT: { expires = Sat, 01 Jan 2000 00:00:00 GMT, content-type = text/javascript; charset=UTF-8, connection = keep-alive, content-length = 0, access-control-allow-origin = *, pragma = no-cache, x-fb-debug = JQD41MeNlCzH9dh+I/ezr8oB1bTDywfF2L25NcnZzchujXV4PMCWJI4r+kOjEy82OgNZ9SKpyNnucPLpAfEVeA==, facebook-api-version = v2.5, date = Fri, 08 Apr 2016 10:16:43 GMT, cache-control = private, no-cache, no-store, must-revalidate, x-fb-rev = 2274481, x-fb-trace-id = DtH4V+9DuTN, }

My code
`local function http_result(self, id, response)
print(response.status)
print(response.response)
pprint(response.headers)
pprint(facebook.access_token())
if response.status == 200 then
local dta = json.decode(response.response)
pprint(dta)
gui.set_text(self.face_node, dta.data[1].score)
else
gui.set_text(self.face_node, “Error: “…response.status…”(”…facebook.me().name…")")
facebook.logout()
end
end

local function fb_score(self)
–pprint("access token "…facebook.access_token())
http.request(“https://graph.facebook.com/v2.5/me/scores?access_token=”…facebook.access_token(), “GET”, http_result)
end`

Thanks for reporting this. It sounds as an issue in the engine and how we deal with HTTP caches. I’ve created a ticket for this: DEF-1743 @Ingela_Garneij, could we try to look into this as soon as possible?

3 Likes

This will be coming in next week’s release. Thanks for reporting it.

3 Likes