Facebook app customization and AJAX response

0 favourites
From the Asset Store
Create your own casino app and import it to Google Play and the App Store.
  • 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:

    {
      "id": "100003234347433", 
      "name": "Ale� Kovacic", 
      "email": "sth@email.com"
    }
    

    Thank you and sorry for my bad English.

  • 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.

  • 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?

  • 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.

  • So how do I use 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.

  • 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.

  • OK. I get URL with token. What do I do next?

  • 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. :)

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

    Thank you so much!

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I'm only using the latest version, not sure how to save it in a previous version. :( Sorry. You might be better off using php for the free edition and using ajax to fetch the data that way. My way sucks up the event count.

  • prntscr.com/kxmyh

    You can try it here: wawhost.com/game

    So... It works! But it takes forever (over 10 seconds) to load AJAX data in chrome for me. For my friend however it loads fast (in 3 seconds).

    Is there something else I should be careful about? Anything I should change?

  • I'm on my iPad at the moment but I'm assuming one of those links is a capx? If so when I turn my pc on ill take a peek. Facebook is always changing so your best bet is to sign up for their developer blog email updates. For example early in December they are changing some stuff around, the again in January. It's about once a month I believe. First change that affected me was how they handle credits. In December imvrequired to show credit pricing in the users set local currency. My code already takes that into account but if it hadn't I'd have credits disabled shortly after the date. They have a pretty lengthy terms of use and privacy rules. So check those out too. For the most part when it comes to the games not a whole lot changes and rules are pretty easy to understand. Fb games are kind of my passion at the moment so feel free to pm me to chat up Facebook topics.

  • Heres how I deal with the url info:

    <img src="https://dl.dropbox.com/u/77974757/facebookurl.PNG" border="0" />

  • There is a condition in the ajax plugin called on complete. Instead of waiting a second use this condition.

    on complete -> fetch data. If ajax takes more than a second you wont get the info your way.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)