Facebook integration with GameSalad • v1 • Oh Yeah! ( With 15 minute Tutorial Video)
StormyStudio
United KingdomMember Posts: 3,989
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.
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.
Comments
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
www.marcosriffel.com
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
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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.
Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.
Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…
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.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
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
$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.
@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.
…..
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...
Website » Twitter » Facebook » Loaded Arts - Fun for thumbs.
Developer Blog » 08/01/2015 - Week 72 – Apple, the great dictator…
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
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
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.
>:)
My GameSalad Academy Courses! ◦ Check out my quality templates! ◦ Add me on Skype: braydon_sfx
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...
Like Balls? Then click here! We've 100 coming soon