connect – Stay N Alive

FBFoundations Facebook Connect Plugin for WordPress

lego bricksOne of my biggest frustrations in adapting Facebook Connect into WordPress blogging has been the fact that most plugins out there either have too much, or too little incorporated into them.  When you add more than one, you end up calling the Facebook Javascript Client libraries more than once, and often reinvent the wheel for what other people have done.  I mentioned this in a wish-list I posted earlier.  I want building blocks – I should be able to add a foundation, and add basic building blocks on top of that foundation to get what I want out of Facebook Connect on my blog.

Today I’m giving you that foundation.  I’ve written a WordPress plugin called FBFoundations which sets up the bare-bones necessities of any Facebook Connect install.  Once you have installed this plugin, the user can log in, and you have access to their login credentials from then forward to do whatever you want with. It’s a foundation – something to build a house on top of, and my hope is that many more FBFoundations-compatible plugins can emerge from this.

For instance, my next step will be to create a simple plugin for WordPress that uses the stream.publish API to post your blog to Facebook, and enable others to do so (tracking the number of comments and likes along the way if possible).  There will be no need to add a user log in to that process, nor do I have to load the XFBML init scripts to render XFBML.  It will all have already been loaded for me.

The script works a lot like Richard Miller’s “What Would Seth Godin Do” plugin from a UI perspective.  At a default (you can configure this in your preferences) the first 3 times a user visits your blog they will be presented with a popup dialog box encouraging them to connect with Facebook.  After those 3 times the popup no longer appears.  There will also always be a “Connect with Facebook” login button above your comments (assuming they’re wrapped in a #commentform div) that will appear until the user clicks on it and logs in.

Using this plugin encourages each reader to log in through Facebook (remember – there are over 300 million Facebook users.  Chances are most of your readers are on Facebook), and enables you to do cool stuff with each of those readers.  Hopefully this will inspire others to make other FBFoundations-compatible plugins so we’re not re-inventing the wheel any more.  Stay tuned for more plugins from me – what will you build with this as your foundation?

You can download the plugin here.  Just download it and unzip it into your plugins directory in WordPress, activate it, and then add the API key for your website.  (You’ll need to go to http://developers.facebook.com to add the developer app and add an app for your website if you haven’t done so already)

Or click here to download:

http://downloads.wordpress.org/plugin/fbfoundations-facebook-connect-plugin.zip

Please let me know in the comments if you see any issues.  This is 100% GPL so please make your own adjustments and let me know if I can fix mine!

UPDATE – v0.4 – 10/26/2009: The popup is no longer default and can be turned on/off. Also added meta tag support and better compatibility with 3rd-party comment systems.  See this blog post for more info on 0.4.

Here are some screenshots:

Screen shot 2009-10-10 at 6.21.49 PM

Screen shot 2009-10-10 at 6.19.47 PM

Screen shot 2009-10-10 at 6.19.13 PM

1 Prediction Down, 7 to Go – Facebook Launches Connect for the iPhone

FacebookBeginning of February I announced my 8 late predictions that I thought would happen in 2009. One of those, which I actually mentioned originally last year, was that Facebook would launch a developer platform for the iPhone. Such a prediction was hinted at last year by Facebook, was supposed to launch end of last year, and it would appear that this morning it came true. As of this morning, Facebook announced they are releasing Facebook Connect for the iPhone, and announced several of the first apps using it.

The platform integrates with the iPhone XCode platform and provides libraries that make integration of Facebook into any iPhone app easy. (Here’s where I get geeky, so beware) Per the documentation, the basics are that developers simply include the libraries in this manner:

#import “FBConnect/FBConnect.h”

Following that, the basic component of the app is the session object. To create a session object, you just need to provide code similar to this:

session = [FBSession sessionForApplication:myApiKey secret:myApiSecret delegate:self];

Following that, you’ll want a basic login button you can provide to users that authenticates the user and connects with the session object. To display the login button, use code like this:

FBLoginButton* button = [[[FBLoginButton alloc] init] autorelease];
[self.view addSubview:button];

Once the user is logged in, the session object should have the session key from Facebook, and you can make normal Facebook API calls from there. From there, you can get the session key and the session secret and send them back to your servers for processing, or make simple calls back to Facebook directly from the iPhone app using the provided libraries. Facebook provides this sample code as an example on how to do it from the iPhone:

– (void)getUserName {
NSString* fql = @”select name from user where uid == 1234″;
NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@”query”];
[[FBRequest requestWithDelegate:self] call:@”facebook.fql.query” params:params];
}

– (void)request:(FBRequest*)request didLoad:(id)result {
NSArray* users = result;
NSDictionary* user = [users objectAtIndex:0];
NSString* name = [user objectForKey:@”name”];
NSLog(@”Query returned %@”, name);
}

It would appear that 2009 is right on track, and I can’t wait to see what more Facebook has in store for us with the recent launch of their new design, new focuses, and more. This alone may be enough to get me even further into iPhone app development as the iPhone finally has the potential to become much more “Social”.