GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

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

StormyStudioStormyStudio United KingdomPosts: 3,987Member
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 Posts: 738Member
    Great Job Stormy! Gettin excited!
  • EireStudiosEireStudios Posts: 451Member
    Great work man, I'm really looking forward to this :)
  • marplumarplu Posts: 412Member, PRO
    Wow! Incredible stuff Stormy!
  • kolabokolabo Posts: 240Member
    Fascinating to follow your progress. Congratulations to you and Jon!
  • jonmulcahyjonmulcahy Posts: 10,384Member, Sous Chef, PRO
  • RiffelRiffel Posts: 1,272Member
    Fantastic! Waiting the tutorial, hope this time I can figure the guide ~X(
  • EireStudiosEireStudios Posts: 451Member
    Very nice! Thanks for sharing your hard work with us Jon :)
  • StormyStudioStormyStudio United KingdomPosts: 3,987Member
    Here are the files I use in the above tutorial...
  • CasualEvolutionCasualEvolution Posts: 434Member, PRO
    Thanks! You are very generous! :)
  • Braydon_SFXBraydon_SFX Posts: 8,981Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee
    Sweet! Thanks for your time and effort, Stormy !
  • rdlew2008rdlew2008 Posts: 85Member, PRO
    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 Posts: 240Member
    @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 Posts: 10,384Member, Sous Chef, PRO
    rdlew2008 said:

    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 Posts: 85Member, PRO
    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 Posts: 85Member, PRO
    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 KingdomPosts: 3,987Member
    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 Posts: 451Member
    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 KingdomPosts: 3,987Member
    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 Posts: 220Member, PRO
    this is soOOOO cooool
  • StormyStudioStormyStudio United KingdomPosts: 3,987Member
    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 Posts: 240Member



    @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 Posts: 85Member, PRO
    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 Posts: 8,981Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee
    @Stormy -- I've distributed the Community Champion badge to you, sir! You've earned it (and probably earned it way before this) !
  • PBEmpirePBEmpire Posts: 676Member
    Man this is insane!!!
  • EireStudiosEireStudios Posts: 451Member
    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 Posts: 9,914Member
    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 KingdomPosts: 3,987Member
    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 Posts: 8,981Member, Sous Chef, PRO, Bowlboy Sidekick GameSalad Employee

    Now we need a GS guru's badge..lol

    ...eh. what about a Bowlboy sidekick badge worth a couple thousand?
    >:)
  • StormyStudioStormyStudio United KingdomPosts: 3,987Member
    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...
Sign In or Register to comment.