How to make a Facebook game

Favourite 278 favourites
Tutorial written by TomOriginally published on 4th, September 2011 - 13 revisions

Integrating the Facebook plugin

Now you have a basic Facebook game or app running on Facebook. Using the Facebook object in Construct 2, you can integrate with Facebook's features.

First of all, drop in the Facebook object to your game. In the properties bar, you need to enter your App ID.

You can get the App ID from the settings page earlier.

If you want to publish hi-scores on Facebook, also enter your App Secret. Do not enter the App Secret if you aren't going to use hi-scores! Entering your app secret is bad practice, but it is necessary to get the hi-scores system to work.

Adding Facebook features

You need to use the Facebook plugin's Log in action to enable integration. You cannot do this automatically: have a button saying "Log in" that the user must click. This will open a popup window and Facebook will request if the user wants to let the app access your account. They have to click Allow to log in.

The user can keep using your app if they are not logged in, but the Facebook plugin won't be able to do anything.

The permissions that the login screen asks the user to approve depends on what you set in the Log In action.

An important point is the fewer permissions you request from the user, the more likely they are to allow. In other words, do not ask for permissions you don't definitely need. Users are prone to avoiding logging in to apps that ask too much.

Here's what the Facebook plugin can do depending on permissions:

No permissions (both set to None)
- You can still get the user's name (e.g. to say "Welcome back, Joe Bloggs!")
- You can use the Prompt to share link, Prompt wall post, and Prompt to share this app actions. These bring up popup windows which the user can OK or cancel. For many games and apps, this is enough - you don't need to request any permissions at all for that!

Publish to stream permission
- You can do all of the above, and use the Publish wall post and Publish link actions. These instantly publish without prompting the user. You should be very careful not to annoy the user or they will ban your application. Always get the user to approve the action, and publish as little as possible.

In fact, this permission is not recommended. It is probably always better to use the Prompt actions which require no permissions, since the user controls what is written and can cancel it. However, the permission is provided in case it is useful to some apps.

Publish scores permission
- You of course get the 'no permissions' features, but you can also use the Scores API.
- This means using Publish score, Request hi-score board and other features. The picture of the login dialog above for Space Blaster shows what the login dialog looks like for this: it requests "Publish games and app activity".

You must also enter your App Secret to use the Scores features. But don't enter your App Secret if you're not using Scores!

Facebook events

The Facebook object has some conditions that can help you determine the state of the user.

Is ready is true if the Facebook object is ready to be used. If it is not ready, the Facebook features are still being loaded. You can't use the Log in action until the Facebook object is ready.

On user logged in triggers after the user clicks Allow on the login screen opened by the Log in action. However, the user's name is not yet available - it will follow shortly.

On user logged in also triggers if the user re-visits your app later, and their login is remembered. It also triggers again for each layout you go to, on the start of the layout. (This is helpful if the user returns to your title screen - the event still triggers.)

On name available triggers a moment after On user logged in. Now the user's name is set, which you can access via the Facebook object's expressions. These expressions will be empty before this triggers.

Share and Copy this Tutorial

You are free to copy, distribute, transmit and adapt this work with correct attribution. Click for more info.


andreyin 28.6k rep

Oh wow, that's simple! I thought I had to convert the code or something. Thanks.

Sunday, September 04, 2011 at 6:06:03 PM
The Bespectacled One 4,890 rep

Publishing my games on the largest current social network? Yes please!

Monday, September 05, 2011 at 2:20:07 AM
ludodesign 30.8k rep

I loved the idea to make directly for facebook, I am testing things in facebook last week, see here my little game maked in construct 2 to facebook =)

Monday, September 05, 2011 at 4:05:08 PM
gaboduarte 13.8k rep

This is amazing, I made a small game and I was wondering if it would be possible to put it on Facebook.

Is there any way to make the game send your highscore to friends, like posting it on their profile?

Monday, September 05, 2011 at 4:32:07 PM
Tom 54.8k rep

It is possible to do high score posting to Facebook profiles yes! But it's a lot more involved. It's going to require a lot more work/research on our part to make it work fluidly with Construct 2 but it's something we want to add in to C2 at some point.

Monday, September 05, 2011 at 5:01:33 PM
harrio 36.0k rep

smiles warmly...

Monday, September 05, 2011 at 8:47:01 PM
gaboduarte 13.8k rep

@Tom: Thanks for the reply!
I'll finish the game first, then I'll see if I can dig something about that. :D

Tuesday, September 06, 2011 at 2:38:58 PM
TheJanMan 4,470 rep

This is just great! I bet Game Maker can't do this.... can they? ={

Saturday, September 10, 2011 at 4:31:56 PM
oreo 7,119 rep

Thanks for the tutorial! It helps me on my demo;

Monday, November 07, 2011 at 8:22:56 AM
squale 8,267 rep

Sorry for my english i am french.
I tried to do a facebook apps but facebook wish the https adress, have you an idee to help me ?

Tuesday, November 08, 2011 at 11:23:46 PM
devilsgarage 3,147 rep

I have to agree with 'squale' above. Facebook is currently asking for "Secure Canvas url" (ref: ) Is there a way to figure out what this means?

Saturday, November 26, 2011 at 10:46:20 AM
guicole 3,570 rep

Hi, I have some trouble using the High score feature on the Facebook object.
And on the Scirra game, Space Blaster, I can see that the high score is always 0, like for my game.
Is that normal ? is there a problem there ?


Sunday, November 27, 2011 at 9:33:55 PM
openabel 2,732 rep

thanks this is great

Friday, December 09, 2011 at 3:19:10 AM
Ulisses 9,513 rep

It's great!

Saturday, December 10, 2011 at 1:57:36 AM
danieltpt 3,323 rep

hi ashley,

thanks for the tutorial on the facebook app.

i tried to follow it but it seems a lot of the steps i cant follow as the screens are different when i log in to facebook.

maybe your tutorial needs to be updated? i would really like to create a facebook app.


Wednesday, December 14, 2011 at 8:41:21 AM

Leave a comment

Everyone is welcome to leave their thoughts! Register a new account or login.