Facebook app customization and AJAX response

Get help using Construct 2

Post » Thu Nov 29, 2012 8:53 pm

Hello,

I'm trying to make a Facebook app but I ran into a few problems.

1. How do I get permissions to get user's email?
I'm using default Facebook plugin that came with Construct 2.

2. How do I extract specific data from AJAX POST response?
I'd like to save user's ID, name and email that I get from AJAX POST response into separate variables. When I use AJAX POST function and request user's info I get this response:

[CODE]
{
"id": "100003234347433",
"name": "Ale Kovacic",
"email": "sth@email.com"
}
[/CODE]
Thank you and sorry for my bad English.
B
9
Posts: 15
Reputation: 607

Post » Thu Nov 29, 2012 9:25 pm

For the question 1 you should probably check this tutorial about how to male facebook game. I quickly checked, page 4 there are informations about permissions.

For question 2 you could use the system expression "tokenat" to help you break down the string.

Make a search on the forum with the keyword "tokenat" (don't hesitate to look into posts older than 6 months) to find examples and more informations of usage.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Thu Nov 29, 2012 10:44 pm

This tutorial isn't useful for me. It doesn't describe how to get emails from users.
I think that I'll have to customize Facebook plugin. But how?
B
9
Posts: 15
Reputation: 607

Post » Thu Nov 29, 2012 11:06 pm

For permissions check the developer.facebook.com site, under one of the tabs is dialogs. You can use the login dialog to request permissions and log the user in. This sends the user token on login in the address bar for ajaxing the graphapi. Then as @kyatric says you can token at the last Ajax.lastdata to split the info by the : key. Then remove the unwanted info using the replace command. I'm building my game Facebook credits system using this exact method.
B
67
S
21
G
15
Posts: 701
Reputation: 15,579

Post » Thu Nov 29, 2012 11:58 pm

So how do I use https://developers.facebook.com/docs/reference/dialogs/oauth/ (https://developers.facebook.com/docs/reference/dialogs/oauth/) in Construct 2?
Do I add AJAX POST/GET action? I've tried both but it doesn't work.
B
9
Posts: 15
Reputation: 607

Post » Fri Nov 30, 2012 12:09 am

It uses browser redirection. So to login in a user you will use the browser plugin to redirect the current website to the URL from the developer site. Make sure you have all the info filled in properly such as the redirect should point back to your website. There's a list on that site of the browser variables, for scope you add the permissions separated by a , and response_type should be token. Using code just forces you to prolong receiving the user token.

After you logged them in use Ajax to get the email address.lanceal2012-11-30 00:13:31
B
67
S
21
G
15
Posts: 701
Reputation: 15,579

Post » Fri Nov 30, 2012 12:38 am

OK. I get URL with token. What do I do next?
B
9
Posts: 15
Reputation: 607

Post » Fri Nov 30, 2012 12:42 am

@Alesko007

I've stripped down my store to just the basics so you can see how I handled the login. You will need to adjust the app-id in both the facebook plugin and event sheet 1. Also the url listed in event sheet 1. As you can see it also can handle if a user revokes permissions. So if someone decides to revoke permissions it sends them to the appropriate layer so you can explain more why you need the info and offer them a button to click and ask them for permissions again. You can also see how I used tokenat and replace to fetch the usertoken I need. It'll be the same concept when using graphapi to fetch the email address.

My store base capx

Anyone that looks at it, feel free to give me tips on further optimizing the event sheet to minimize the number of events. :)
B
67
S
21
G
15
Posts: 701
Reputation: 15,579

Post » Fri Nov 30, 2012 12:47 am

I'm using free edition. Could you save it in Construct 2 r108.2 version?

Thank you so much!alesko0072012-11-30 00:48:33
B
9
Posts: 15
Reputation: 607

Post » Fri Nov 30, 2012 12:49 am

For the ajax email if I remember right you 'GET' the following address:

'https://graph.facebook.com/userid?fields=email'

the just tokenat and replace the information you don't need to strip it down to email.
B
67
S
21
G
15
Posts: 701
Reputation: 15,579

Next

Return to How do I....?

Who is online

Users browsing this forum: mercuryus, mystazsea and 18 guests