Sp4ce.net rss

Automatic answer on a facebook page

Facebook page allows to programtically send message if you know how to trick the API.

Facebook Page: Santa Claus

Facebook page is a way to promote your business or someone. In the company I work, we decided to make a Santa Claus page that is in fact a bot that replies to user comments on the wall. It is really fun to see people interact with it, and we currently have 120 000 fan on the page. The page in the French, but please have a look.

The architecture needs a fb connector that:

  • polls the fb page
  • get the answer for the bot
  • post the answer to the corresponding conversation

In this post, I give more details on how do a programatic post on a facebook page wall, answering a comment of a user.

Posting Message

Facebook has a fully REST API that is know as the open graph API. There are various library on the web to connect to it, using C#, JavaScript or php. Please visit the facebook SDKs & tools page to know more about that, and the graph API page about the API itself.

Once you know that, have a look at

The first request is the publis Santa Claus page, it gives you general information about the page. However, the second gives you the stream of the page wall (GET) or allows you to post content to the wall (POST), then you should get this message:

    error: {
        message: "An access token is required to request this resource.",
        type: "OAuthException",
        code: 104
    }

You need an access token to access the resource. If you want to know more about access token and OAuth 2.0 authentication and authorization, please do, but here, the only thing you need to know is that access token is the way to say to facebook: hello, I am this guy and I have the right to do that and that. Once you have the access token, Facebook trusts you.

Access Token

In order to get an access token for your page, you need an application key and of course a page. In order to create the application, go to My Applications page and create one application. Now you need to setup a temporary site url in order to execute a small JavaScript code that will help you to get the access token.

You need:

  • site url: http://www.sp4ce.net/facebook/access_token
  • domain name: sp4ce.net
facebook_app_config facebook_app_config

Then you can go to http://www.sp4ce.net/facebook/access_token, enter the application id and click enter. You can check that the permission given if enought but it should be ok. You should be request to give some access to the applicatio you just created and after 1 second, you will see a table with the access token

Enjoy !