There are a number of Facebook tutorials, including my own offering examples of FBML to add additional functionality to a Facebook fan page.
However, on many occasions these tutorials fall short of the mark, with no server side functionality currently available via FBML, connecting to databases, or consuming information from other sources is difficult.Third party services fill the gap, but are often expensive, or cumbersome to implement.
One of the most common questions I get asked regarding FBML is how to integrate a WordPress blog, or blog posts on a Facebook fan page tab. This tutorial takes you through the steps of doing just that, with no third party application required.
For my own Facebook page, I have opted to offer exclusive content (not available on my main blog) via Facebook. In addition to that, fans and non fans see a different opening tab, giving them incentive to ‘Like’ the page.
Here’s what we are going to end up with:
1). A tease and reveal tab created via a Facebook application
2). Exclusive content which is only available to Facebook fans
3). Some added spice in the form of Facebook Javascript (FBJS) to cycle the posts elegantly.
Here’s what the final result looks like:
See the example live here. (Obviously) you’ll have to fan this page to see the posts.
Step by Step
Here’s what we need to do. Step by Step.
1). Create a new WordPress category to house the exclusive content
2) Find the new category ID
3). Exclude the category ID from your RSS feed and main blog
4). Obtain a Facebook application key and application secret
5). Download the latest Facebook libraries.
6). Setup a directory in the root of your WordPress install
7). Ammend and upload the required files
8). Change Facebook application settings to point to your new files.
Step 1. Create the new category
A relatively simple process, creating a new category in WordPress is as simple as going to the category section and adding the details. Further information (for those who need it) can be found on the codex.
Doesn’t really matter what you call this. The important part of the process, is working out what the unique “category ID†for the newly created category is.
Step 2. Find the new category ID
The category ID can be found simply from within the WordPress admin section. When you have created the new category simply hover over its name, and you’ll see this in the toolbar..
Unsurprisingly, cat_ID represents the new category ID. Keep this handy, as you are going to need it to exclude the category from your main blog.
Step 3. Exclude the category
There are three places we are going to remove this category. One is the sidebar of your WordPress blog, the other is inside the main blog loop – and finally the third is your RSS feed.
1) Removing from the sidebar
See Under ‘ Hiding the category for the sidebar‘ in this post, which uses a very similar technique to create a custom newsletter using WordPress.
2 & 3) Removing from the main loop and RSS
I’ve used a custom plugin that I’ve created to handle this. You can download it here, but please remember to set the $category_id_to_remove variable at the top of the plugin prior to upload. It looks something like this for you code junkies curious.
add_filter('pre_get_posts', 'exclude_category');
function exclude_category($query) {
//HEY YOU! - REMEMBER TO SUBSTITUTE THIS VARIABLE NOTICES THE MINUS SIGN TOO.
$category_id_to_remove = '-1127'; // this should be changed to the catID
$query->set('cat', $category_id_to_remove);
return $query;
}
?>
Ammend, upload and install in the usual way that plugins are installed. To test that you have successfully excluded the category, simply create a post and assign it to that category. It shouldn’t appear in either your RSS feed, or your main blog. Sorted.
Step 4. Facebook app keys
To obtain Facebook application keys, you’ll have to create an application first. Visit this URL to begin the setup of a fresh application. You can call this whatever you like. Accept the terms and click next, you may be required to fill in a captcha prior to moving on. You’ll be presented with a number of options, which we will have to fill in later. Right now, the only tab you are interested in is the “Facebook integration†option. You should be able to click on that to obtain both the ‘application secret’ and ‘application key’. Save these as you’ll need them for later steps.
Step 5. Facebook API Libraries
Facebook don’t make things terribly easy for developers, as there’s a fair bit of hunting around before finding the API libraries for PHP. They do however make life much easier for getting the information out of the Graph API.
These are currently housed at Githubs, and are available via this download link.
Download and extract the class (facebook.php). (As this file may change / get updated). I have however included this at time of writing in the main demo download below.
Bear in mind that this is the new Graph API – and not the old Restful API.
Step 6. Setup a directory
You can do this locally, prior to installation. You’ll need a directory for images, and the main code files which I’ve already written for you.
Download the full zip folder here.
These connect through to WordPress etc . Should look something like this.
Facebook.php – The main API class downloaded earlier
incfunctions.php – Any additional PHP functions (I’ve used a trimming function to shorten my posts)
Index.php – The main FBML page used by Facebook
tinthumber.php – A generic image resize PHP script, makes things pretty.
Step 7. Ammend the files
The only file that you will have to deal with is “index.php†everything else should be fine as is. The following are the sections of code that may need tweaked.
Lines 7 & 8:
$appapikey = ‘YOUR API KEY HEREâ€;
$appsecret = ‘YOUR APP SECRET HERE’;
refer to Step 4 if you can’t remember what these are.
Line 9:
$main_app_location_http = ‘http://www.yourdomain.com/facebook/’;
Change this to whatever server domain you’ve installed on. Will be the same as the domain for your WordPress install, inside a sub directory.
Line 48:
$number_of_posts = 5;
Change this to determine the number of WordPress posts that will be shown / cycled through inside your FBML application.
Line 54: IMPORTANT
AND $wpdb->term_taxonomy.term_id IN(1127)
Change 1127 to be the same category ID that you determined in Step 2.
Line 110:
Determines what image / HTML to show to visitors who aren’t currently fans of your page..
Save the file with your settings, and upload it. At this point viewing the URL in the browser (http://www.yourdomain.com/facebook/) should show you the content shown at line 110.
Step 8. Change Facebook settings
Now that your application has been created, and uploaded, all that is left to do is to perform a few tweaks to the application page to set it all up. Log back into Facebook and follow these steps:
To set the app settings
1) Visit the following Developer Apps URL
2) Select the application name that you set in step 4 and click edit settings.
3) Click Facebook Integration
4) Set the canvas page name to anything you want
5) Set the canvas URL to the HTTP location you uploaded everything to. (Will be the same as the variable $main_app_location_http used earlier.
6) Set canvas type to FBML
7) Set tab name to ‘Extra content’
8) Set tab URL to ‘index.php’
Save changes and click ‘Back to My Apps’ at the top of the page.
To add the application to your fan page
1) Click Application Profile Page
2) Click ‘Add to my Page’ – if you an admin of several fan page, select the appropriate one.
3) Visit your fan page
4) Click the + icon beside your tabs, and select ‘Extra Content’
Voila! That should be you up and running now, having created your first Facebook FBML application. Simples!
You should be able to expand upon the code that I’ve provided, and I’ll be adding to my own offering as I now have a fair idea how things work. Next stage will be to perhaps syndicate some RSS, or integrate my Twitter account.
Articles which proved to be useful:
Facebook JS slider – I’ve used a large proportion of this code to give the sliding left and right effect.
How to detect fan of a Facebook page. – Hooray for the REQUEST object giving additional information from Facebook. var_dump to the rescue.
Some things developers need to know when developing for Facebook
JQuery isn’t supported, Facebook don’t allow you to link to external scripts when creating a canvas application. Instead a JS library called FBJS is used. That said – an open source project to mirror JQuery functionality inside Facebook looks promising.
Body tag’s are not allowed inside FBML canvas.
When creating an application for a tab, some functionality will be restricted, particularly user auth calls as tabs can’t redirect.
$is_fan = $_REQUEST['fb_sig_is_fan']; this code works out if the current user session is a fan of the page or not without needing to find the user ID. The above paragraph explains why userId can’t be fetched normally.
Facebook tab widths for designs are 520px.
Finally..
You can of course change the images which are used, and the surrounding HTML to create your own custom FBML app. Standard WordPress programming can be used because of the inclusion of the core libraries at the top of the script, so those of you familiar with writing plugins or custom code should be right at home. Let me know your thoughts in the comments.
How to (fully) integrate WordPress with Facebook is a post from: Webdistortion
Why You Shouldn’t Use Facebook Comments… Yet
Earlier this month, Facebook announced some significant upgrades to its commenting system for bloggers and other website owners.
The system is designed to compete with services like Disqus and Intense Debate by adding a Facebook-hosted commenting system to your site, one that can either replace or supplement your existing comment system.
To their credit, Facebook has given a lot of reasons to like the system. It’s clean, easy to look at, has good moderation tools, great stat reporting and is virtually spam-free since users have to have a Facebook account to comment.
Because of this, many sites, including TechCrunch, have begun either using or experimenting with Facebook comments.
However, this system is far from a match made in heaven and you won’t see it on my site, at least not in its current incarnation. Where it might be for some, it isn’t for mine and I will do my best to explain exactly why.
Problem 1: Out of Sync
With Disqus, which is what I currently use, and Intense Debate comments posted to your blog get put both in their database and yours. This means that, should you decide Disqus/ID is no longer right for you or if the company closes for some reason, you still have your comments.
With Facebook, the comments are simply stored in Facebook’s database and are served via an embed. If you ditch Facebook, you lose your comments, that simple.
Problem 2: JavaScript and SEO
For many sites, the comments is a significant percentage of the content on their page. However, Facebook displays that content in an embedded JavaScript that is not readable or indexable by search engines. This means you get no SEO benefit from your community.
Facebook comments is not SEO friendly and this is a problem both Disuqus and ID deal with gracefully, but putting the comments in your site in cleartext.
Problem 3: Limited Audience
It may be a surprise, but not everyone has a Facebook account and, those who do, not everyone is comfortable using their account to post comments on random sites. In short, you’re limiting your potential commenting pool to only those with Facebook accounts that trust you enough to use it on your site.
TechCrunch noted that, while Facebook Comments did help keep the trolls at bay and raise the level of discourse, the number of comments has fallen and this is on a very tech-savvy site where nearly every visitor will have a Facebook account.
Problem 4: Technical Difficulties
I attempted to set up Facebook Comments on my site temporarily to see it in action but failed completely. Even using a WordPress Plugin dedicated to the cause, I had no luck in getting it to work, even after disabling every other Facebook-related thing on my site.
Facebook Comments simply doesn’t play nice with a lot of other features and it seems others have had struggles with it as well.
Problem 5: Lack of Customization
Don’t like the way Disqus looks? Customize it. Don’t like the way Facebook Comments look? Tough.
Though the Facebook commenting system is far from ugly, if it doesn’t fit your theme you’re pretty much out of luck. You get what Facebook gives you and, apart from a few subtle changes you can make, there isn’t much anyone can do with it.
Bottom Line
To be clear, there is a lot that I do like about Facebook Comments and I have a lot of reason to want to play with it. But, right now, there are simply too many problems with it for me to consider using it, at least as my exclusive commenting system.
Obviously, I don’t need all of these above problems fixed (customization is not a major issue for me) but I would like to see better SEO handling and synchronization with my local database. Without those two things, Facebook and Facebook alone reaps the benefit of my comments section, leaving me with nothing.
It seems, however, that much of this comes from Facbeook’s tight control over everything that passes through it Facebook doesn’t like to share the information it gets with other domains, even when it comes from another site, and likes to be the sole determiner of how the information it gets is used, often to the chagrin of its members.
In short, until Facebook’s approach to commenting is a little more balanced. I don’t think I’ll be using it on my site, at least not as my main comment form.
Copyright © 2011 Blogging Tips. This Feed is for personal non-commercial use only. If you are not reading this material in your news aggregator, the site you are looking at is guilty of copyright infringement. Please contact us so we can take legal action immediately.
POSTLINK
A selection of e-books to help you improve as a blogger. Find out more at www.bloggingtips.com/books/
Posted in Google Reader