Post a Message on a Facebook Wall with JavaScript | WebReference | WebReference

Post a Message on a Facebook Wall with JavaScript | WebReference

By Arpan Dhandhania


Until a few years ago, the buzz word for web developers was "SEO." In simple words, Search Engine Optimization (SEO) means that the developer optimizes a Web page so that when an Internet user searches for something on Google, the page in question appears as close to the first result as possible. SEO used to be the only way to increase traffic to your site. But as you know, in all technology, and more specifically in Internet-related technology, things change at a rapid pace. Somewhere around 2004, the Internet gurus started talking about new Web that was labeled Web 2.0. One of the side effects of Web 2.0 was the increased popularity of social network sites and micro-blogs like Facebook and Twitter.

In today's scenario, traffic to most websites is still primarily driven from Google and other search engines, but there is a substantial amount of traffic that comes from people posting links on websites like Facebook and Twitter. The traffic that comes from these social network websites is potentially quite different from that which comes from search engine result pages. When a user is sent to your website from Google, you can be quite certain that they are specifically looking for the content you are providing on that page. However, the user that comes to your site from either Facebook or Twitter may have clicked on the link only because a friend of theirs published the link. The user may be completely oblivious of the domain of the content and may exit the page in a matter of seconds. Anyhow, at the end of the day, the number of visits to your site shoots up, and that's something that brings a smile to every developer's face.

Creating a Facebook App

To be able to post a message from your website to the user's Facebook wall, you first need to create a Facebook application if you haven't already done so. Here are the steps to create a Facebook application:

  1. Go to and login to your Facebook account.
  2. Click on the 'My Apps' link in the top navigation bar.
  3. Towards the top of the page, you will find a button titled 'Set Up New App.'
  4. Give your app a name. This is what will appear below the message that is posted on the user's wall.

    Post a Message on a Facebook Wall
  5. After you submit that form and enter the security key, your app will be ready for use. You are free to fill in all the details about the app, but in order to post messages from your website using JavaScript, a couple of fields are mandatory.

    Post a Message on a Facebook Wall

Facebook serves requests to post messages to a user's wall only from the specified domain or subdomains under that domain. So you need to specify the site URL and site domain from which you are going to be posting. If you don't have access to a domain that is publicly viewable, you can always set up a local webserver on your machine and add a dummy domain to your configuration.

That's it! You are done setting up things on the Facebook end.