Facebook integration with GameSalad • v1 • Oh Yeah! ( With 15 minute Tutorial Video)

StormyStudioStormyStudio United KingdomMember Posts: 3,989
edited July 2014 in Working with GS (Mac)
Here's a video to show how my attempt at integrating Facebook with GameSalad is going so far:

This makes use of the multiplayer tools (currently only available to pro members in the nightly builds)

Basic Setup:
1. Server with a MySQL database
2. App ID created on Facebooks developer Site
3. Login PHP script (gets user to login to Facebook and requests access)
4. CallBack PHP script (receives access token, downloads Users Facebook Friends List and saves to a database table)
5. sendtoGS PHP script (reformats table into string and sends out for GameSalad to read)
6. GameSalad game (puts the string into a table)
7. Facebook friends list with ID's now in the game to be used for all manner of cool things.



Many Thanks to @jonmulcahy for his help on this and his tutorial on setting up a local server using MAMP and demon like PHP wizardy.

Once I've got a few more things up and running I'll try and put together a tutorial on how some of this is done. Particularly the Facebook access and requesting info.

«1

Comments

  • zweg25zweg25 Member Posts: 738
    Great Job Stormy! Gettin excited!
  • EireStudiosEireStudios Member Posts: 451
    Great work man, I'm really looking forward to this :)
  • kolabokolabo Member Posts: 240
    Fascinating to follow your progress. Congratulations to you and Jon!
  • RiffelRiffel Member Posts: 1,272
    Fantastic! Waiting the tutorial, hope this time I can figure the guide ~X(
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    So here it is…

    a 15 minute long tutorial of me babbling on about how to get access to Facebook, save a users friends list to your MySQL database and send that out to GameSalad.

    TUTORIAL FILES INCLUDED IN NEXT POST

    THE VIDEO IS CURRENTLY UPLOADING.. AND I'M HITTING THE HAY, IT SHOULD BE UP AND PLAYABLE BY 12:05am GMT.. … Unless my broadband cuts out whilst I'm dreaming of PHP code...




    1 • Put a new database and table on your already running local server

    2 • Put the needed PHP files in the correct local server folder


    3 • Create App on Facebook developer site
    - Get App Id and Secret Code
    - Add the required URL information in 4 places.


    4 • Update each script with the App Id, Secret code, URLs and database/table names. Plus a rough run through of what's going on in each of the three scripts.

    5 • Trickest part I try to explain is toward the bottom of the callback.PHP file where you need to ensure the file you output from your Database is formatted exactly the same as the way GameSalad sends out its JSON files.

    • Put correct URLs in the GameSalad Demo,

    • Then running the demo… Success!!


    PLUS HERE'S SOME USEFUL INFO ON CUSTOMISING THIS FURTHER:

    PERMISSIONS AND DATA:

    • Facebook Permissions for apps:
    https://developers.facebook.com/docs/reference/login/

    • What data is accessible from a friends list:
    https://developers.facebook.com/docs/reference/login/public-profile-and-friend-list/

    Facebook login using Service Side Code and the URL behaviors

    Facebooks official info on building a manual login
    https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow

    Tutorial for the PHP script that mine is based on.
    http://hayageek.com/facebook-dialog-oauth/


    I hope you like the video and it all makes sense.

    Good luck

    Jon

  • EireStudiosEireStudios Member Posts: 451
    Very nice! Thanks for sharing your hard work with us Jon :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Here are the files I use in the above tutorial...
  • CasualEvolutionCasualEvolution Member, PRO Posts: 521
    Thanks! You are very generous! :)
  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271
    Sweet! Thanks for your time and effort, Stormy !
  • rdlew2008rdlew2008 Member, PRO Posts: 85
    This is awesome i cant thank you enough for your time and effort !!!!!

    quick question

    I am not using a mamp server i am using one threw a server provider. arvixe is who i use for my websites.

    so for this in the callback.php

    $port = '3306';
    $link = @mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');

    should this be changed?? still working threw the tutorial but figured this might cause problems later.
  • LoadedLoaded Member Posts: 240
    @StormyStudio this cool man, but excuse my ignorance... what could you do with the facebook data once you've harvested it?

    Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

    Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    This is awesome i cant thank you enough for your time and effort !!!!!

    quick question

    I am not using a mamp server i am using one threw a server provider. arvixe is who i use for my websites.

    so for this in the callback.php

    $port = '3306';
    $link = @mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');

    should this be changed?? still working threw the tutorial but figured this might cause problems later.
    yes you will need to find out what your host uses and update it with that.

    i think it will be MUCH easier to just download and install MAMP for now (it's free) and use that for testing. once you have this working locally I'd worry about getting it working with a host.
  • rdlew2008rdlew2008 Member, PRO Posts: 85
    edited January 2014
    Thanks!! I figured i would try localhost but i may take your suggestion because when i hit the facebook login i get from fb

    An error occurred. Please try again later.


    Could this be causing fb to not like things or is this a facebook problem


    **edit** got that to work had to set the app to live.

    now getting Error: Could not connect to MySQL server.

    I submitted a ticket to arvixe with the path to MySQL.sock
  • rdlew2008rdlew2008 Member, PRO Posts: 85
    It works!!!!

    $link = @mysql_connect(':/Applications/MAMP/tmp/mysql/mysql.sock', 'root', 'root');

    equals

    $link = @mysql_connect('localhost', 'database name', 'database password');

    Wrote to the table in my data base all my friends name and fb id.

    This is going to be great for promote app threw facebook.

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    Glad everyone likes it…

    @rdlew2008 that's awesome…. glad you've got it working and writing to your database already.

    @Loaded the potential with what you can do with this is pretty huge… Here are a few scenarios.

    - Allow the player of your game to select a friends name and invite them to play the game. (Look into PHP scripts on inviting friends once you have achieved access to someones Facebook).

    - Post scores and achievements to a players wall (you need to ask for another access privilege to post to walls).

    - Save all your players own Facebook details (Facebook ID, alongside theirs Playstogether ID). Then when a player lets you see their friends list, you can compare Facebook ID's and let them know if any of their friends play the same game. Then invite them to play the game using the Playstogether network.

    - You can also save the players email addresses (don't think you can get their friends email addresses) if you bring in their own Facebook info. (you have to request email). You could then build up a collection of emails and email them any game marketing news etc … (annoy them with SPAM they might like).

    - It also introduces the basics skills that you could build on to create your own asynchronous game server and bypass using the Playstogether option. Using MysQL, PHP files and send and receive data.

    - A similar method is probably possible with other social networks, i.e. Linked In, Twitter etc.. You'd have to research their APIs.

    Hopefully at some point GameSalad will add the Facebook functionality that Playstogether has (I'm not entirely sure what it is they offer) which might reduce the number of some of the steps I've taken so far. Perhaps it could all be done in app without any need to go to an embedded browser.


    ….

    To get access to a users own Facebook details…

    Instead of this:

    //LETS GET THE USERS FACEBOOK FRIENDS LIST (If you want the users own info remove '/friends' from the below url
    function getUserDetails($access_token)
    { $graph_url = "https://graph.facebook.com/me/friends?access_token=". $access_token;
    $jsonFile = "$json.txt";
    $fullArray = 'fullArray.txt';


    ………….
    you could use this:
    …………..


    //LETS GET THE USERS OWN FACEBOOK DETAILS
    function getUserDetails($access_token)
    { $graph_url = "https://graph.facebook.com/me?access_token=". $access_token;
    $jsonFile = "$json.txt";
    $fullArray = 'fullArray.txt';


    SEND USER TO SUCCESS SCREEN:
    The code to redirect the user to a website after running the call back script is at the top of the callback.php script.

    /*
    header("Location: http://www.yourwebsite address that the user is sent to on success.php"); // change this ...
    */

    delete the /* and */ bits above and below it to bring it to life.

    It's worth noting, if the redirect address is running you won't see any errors codes.



    Also when testing out your setup you will want to constantly clear your browser cache.

    …..
  • EireStudiosEireStudios Member Posts: 451
    edited January 2014
    I wonder if it would be possible to send a image from the creator to a php script and post it to a users Facebook wall (Player has achieved X on Game) hmm I'll have to look into this to see if php can handle receiving images, it would be an awesome way to promote your game with some in game art :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    I wonder if it would be possible to send a image from the creator to a php script and post it to a users Facebook wall (Player has achieved X on Game) hmm I'll have to look into this to see if php can handle receiving images, it would be an awesome way to promote your game with some in game art :)
    Nice idea… but at the moment we can only send a text string from Creator.. which is recompiled in the PHP… but maybe if we're really nice to @CodeWizard he could roll up his sleeves and quickly add support for sending a still ;-)

    Hmm… you could set it up to export your score.. and have some impressive Voodoo code server side create a jpeg with the given score in and post it to Facebook…

    Or send out a code from GameSalad that signifies an achievement and have a jpeg ready and waiting on the server to be posted to Facebook...
  • lebiscuitlebiscuit Member, PRO Posts: 220
    this is soOOOO cooool
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited January 2014
    Thanks @lebiscuit , it is pretty darn cool… now I want to tackle two more things before looking at playstogether a bit more..
  • LoadedLoaded Member Posts: 240


    @Loaded the potential with what you can do with this is pretty huge… Here are a few scenarios.

    - Allow the player of your game to select a friends name and invite them to play the game. (Look into PHP scripts on inviting friends once you have achieved access to someones Facebook).

    - Post scores and achievements to a players wall (you need to ask for another access privilege to post to walls).

    - Save all your players own Facebook details (Facebook ID, alongside theirs Playstogether ID). Then when a player lets you see their friends list, you can compare Facebook ID's and let them know if any of their friends play the same game. Then invite them to play the game using the Playstogether network.

    - You can also save the players email addresses (don't think you can get their friends email addresses) if you bring in their own Facebook info. (you have to request email). You could then build up a collection of emails and email them any game marketing news etc … (annoy them with SPAM they might like).

    - It also introduces the basics skills that you could build on to create your own asynchronous game server and bypass using the Playstogether option. Using MysQL, PHP files and send and receive data.

    - A similar method is probably possible with other social networks, i.e. Linked In, Twitter etc.. You'd have to research their APIs.

    Hopefully at some point GameSalad will add the Facebook functionality that Playstogether has (I'm not entirely sure what it is they offer) which might reduce the number of some of the steps I've taken so far. Perhaps it could all be done in app without any need to go to an embedded browser.

    Awesome, got loads of potential. You're a legend for giving this to the community :)

    Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.

    Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…

  • rdlew2008rdlew2008 Member, PRO Posts: 85
    I am about to pull my hair out and throw my computer across the room.

    I have made your template work. now i am trying to add another table.
    I cannot get from anything but your Faceboo table
    I have tried mirroring everything perfectly in my own project
    i have tried adding a new table in your template

    i dont understand how this is possible
    is there something i am missing.

    and it will only use the one you had already made
  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271
    @Stormy -- I've distributed the Community Champion badge to you, sir! You've earned it (and probably earned it way before this) !
  • PBEmpirePBEmpire Member Posts: 676
    Man this is insane!!!
  • EireStudiosEireStudios Member Posts: 451
    edited February 2014
    @Stormy -- I've distributed the Community Champion badge to you, sir! You've earned it (and probably earned it way before this) !
    And well deserved too! :)
    Does @jonmulcahy have this badge because I think he deserves it too. The two of these guys have done some awesome stuff over the last week and didn't think twice about sharing it with the community. Thanks again guys!
    Jason.

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yes Jon has the badge. Most of us longtime contributors have this badge. Well done @stormystudio long overdue! Now we need a GS guru's badge..lol
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    @Stormy -- I've distributed the Community Champion badge to you, sir! You've earned it (and probably earned it way before this) !
    @Braydon_SFX thanks for the badge… I didn't even know I wanted one but its very cool.. so thank you.

    Glad the tutorial is being appreciated, I think there are ways to improve it… working on a little idea that may or may not work at the mo.. In between catching up with visiting friends and managing a damn cold surf this afternoon.

    @rdlew2008 I'll message you to see if I can help you find out what's going on.


  • Braydon_SFXBraydon_SFX Member, Sous Chef, PRO, Bowlboy Sidekick Posts: 9,271
    Now we need a GS guru's badge..lol
    ...eh. what about a Bowlboy sidekick badge worth a couple thousand?
    >:)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Hi all..

    I've attached an updated 'loginwithfb.php' script.

    This has an automatic redirect to Facebook where a user will be asked to login if not already logged in and then approve any permission requests. So the user does not have to press a login with Facebook button on the first loginwithfacebook.php webpage. This makes it a little smarter as they would already have pressed login once in the game before opening up the embedded browser.

    The script has a clever work around to allow you to do a redirect to the Facebook Oauth login page with the need for them to press a button. (A redirect it seems is normally done in the header text of the script, but we need to build up the url in the PHP code first. So the redirect is triggered later.

    It just takes out one small step for the user…

    File attached...
  • jigglybeanjigglybean Member Posts: 1,584
    Many thanks to all those who have created this. It certainly takes GS in a whole new direction once the nightly build goes live.

    Like Balls? Then click here! We've 100 coming soon

Sign In or Register to comment.