![]()
I’d like to announce the release of my Unity-Facebook API, complete with a sample game, “Color Matching”. This has been my side project for a week and I’m very happy to release this to the Unity community for their own use. Release 1 contains all the Unity project files and PHP web files required to have this application incorporate Facebook data (and pictures) into the game, but does not include the tutorial material. It is intended for advanced programmers who can look through this without guidance.
You can find the latest information and download the project here.
Donations
This project is provided free-of-charge, for personal or commercial use. I ask anyone who finds it useful or informative to feel free to donate if they’d like. This will continue support and advancement of the Unity-Facebook API, and other community projects. Thank you.
Tutorials
Release 1.1 will come out this week with a step-by-step walkthrough of each function within this applicaton. Feel free to explore the scripts and project files and see if you can figure it all out yourself.
Within the Unity assets, I’ve separated the Facebook files from the Game files, so it is clear which assets belong to each part. I apologize, but the naming conventions and syntax in the two parts differ slightly (the game scripts were written many months ago, versus the Facebook scripts which were written this week). Also, I use an excessive amount of blank spaces to align text so it is more pleasing for me to look at. It is by no means a ‘standard’ to anyone but myself.
A Brief Explanation of the Process
Without going into too much detail, I will explain how my application interfaces with Unity.
When you visit the application page, the Facebook UserID is written into a JavaScript function on index.php, which will be called by the Unity Application. This is how the application knows who the user is. At the same time, process.php is writing the user information (and updating friend information, including friend connections) into a mySQL database.
During runtime, Unity doesn’t communicate with Facebook. Unity uses the WWW class to communicate with PHPHandler.php, which reads/writes to a mySQL database which contains all the information you will need.
When a score is achieved, it is sent to the database to be saved, then the user information and ranking information is again requested from the database.
That, in brief, is the flow. The Facebook information is loaded into a database, and from there the Unity app performs just like any other web application.
Facebook Privacy Policy
Facebook requires all data which is not storable data to be removed (or refreshed) every 24 hours. The only piece of information you’re actually allowed to store more than 24 hours is the Facebook ID of your users. In Release 1.1 I will also add the script for a Cron Job, which I will run hourly to clean away data older than 24 hours (please keep in mind that the data table timestamps in Release 1 do not function at the moment).
When a user starts the app, it refreshes their row in the data table with their name and profile picture. It then also will refresh the row of any of their friends who also use the app and are current users of the app. I commented out the DELETE portion in process.php, but in 1.1 process.php will remove anyone who is not a current user of the app.
I recommend everyone take user privacy seriously. It is because of abuses from developers that Facebook (and Apple) make it more difficult for our applications to be approved, and make our potential audience more wary, and less trusting.


Hi Tempest, i wanna say u r doin a great job with facebook&unity API.
Actually i’m tryin’ to understand all the steps involved in the communication between.
I uploaded all files to my server but unity can’t read my base data.
I checked my user is in the users table but unity can’t read the data (no name, no photo, no friends…nothing).
What do u think is my mistake?
Thx for all…..keep your awesome job. Sorry about my english…i’m from spain.
Thanks for the great tutorial. Great idea, and appreciated. I’ll be sending a donation today.
I’m a Unity / C guy so having a bit of trouble with the back-end stuff.
I got the unity project running OK from website, and from within facebook, but without any on the FB functionality working…
I suspect my DB is the issue…
Your tutorial says, make a Database, and… “mySQL_Tables.txt will set up the required tables to my specifications”
So what do I do with the txt file? Does it just get uploaded to the website with the other web files ? or do we need to run it on the database via a command line or script or ssomething… sorry if its a lame question.
thanks, and keep up the good work.
I can’t subscribe to your RSS feed. Please help?
What are you using to subscribe, and what Feed URL are you using? I know for Thunderbird, you have to use “http://” instead of “feed://”, but it works fine.