Facebook makes it very easy to add comments to a website but with their old api and new api and updates its often difficult to follow what you should and shouldn't be doing. In the end the code was very simple but it took us a few rounds to get it correct. Bluetube interactive implemented facebook comments for one of our clients Ticket Alternative as follows :
Setup your commenting "app"
First you need to create an app for your comments and if you have multiple websites I'd suggest creating an app with a unique name.. You do this under "my apps" in your facebook account, you can read more about it
here.
You should now have an app id, and you'll want to cut/paste this somewhere for easy retrieval, it will look something like :
204151772941335
(example app id, don't use it)
Getting the code
You can then get facebook to generate the comment code for you
You then need to paste that code into your page, correcting the appid if its wrong ( I have multuple app id's so it chose the wrong one)
The code will look something like this :
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=204151772941335&xfbml=1"></script>
<fb:comments href="example.com" num_posts="2" width="500"></fb:comments>
I changed the num_posts to 10 and I also had a function on my clients website to generate the URL ( its .net) so mine looked like this
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=204151772941335&xfbml=1"></script>
<fb:comments href="<% =this.GetFriendlyURL() %>" num_posts="10" width="500"></fb:comments>
I wanted to moderate comments so I had to add two meta tags to my main page ( this is a .net site with master pages so I had to add it to my master page)
< meta property ="fb:app_id" content ="204151772941335">
< meta property ="fb:admins" content ="somemadeupfacebookname,anotherexamplefacebookname">
Results
Voila, we have comments on our clients event pages
Thanks for showing the stuff, best example ever - much easier & cleaner than the original example from FB :-)
Greets
Posted by: Lelala | June 02, 2012 at 02:16 PM
If FaceBook changes anything, I won't know about it until I read about the changes in the online news services.
Posted by: Web App Development | October 24, 2012 at 02:20 AM