I've published a new module to CPAN this week called Facebook::Graph, which allows you to interact with Facebook to query data, publish content, and more using the new Graph API that they released at the F8 conference at the end of April. I want to take a few minutes to introduce you to the module.
Full disclosure: I'm should note that I'm not a fan of Facebook. I despise it. Unfortunately it has become so prevalent in our culture these days that you practically cannot do business without it. That said, after spending the last few days with their Graph API, I've become a big fan of the effort they've put into integration.
Anybody who's worked with Facebook in Perl has undoubtedly used the venerable WWW::Facebook::API library. I find that module absolutely amazing, in that with it you can reasonably navigate the absolutely terrible old Facebook API. Honestly, the only complaint I have with the module is that it uses the old Facebook API and therefore creates some sharp edges in your application that shouldn't have to be there. It is with that complaint that I started my work with the Graph API.
I won't bore you with any of the trials and tribulations I had as I was building it this week, but the module is finally in a usable state (at least for querying data), so I thought I'd share with you just how easy it is get stuff done with it. Let's start with something easy, let's find out what public information is available about the Perl page on Facebook.
my $fb = Facebook::Graph->new;
my $perl_page = $fb->fetch(16665510298);
That will give us a hash reference like this:
id => 16665510298,
name => "perl",
picture => "http://profile.ak.fbcdn.net/object3/971/88/s16665510298_4031.jpg",
link => "http://www.facebook.com/pages/perl/16665510298",
category => "Technology",
founded => "1987",
fan_count => 3030
That is of course very easy, but we can do things that are more difficult very easily as well. For example:
my $results = $fb
Says, "Give me the user ids and full names of all users that have the keyword 'Dave' in their user record, and that have been created since yesterday, and limit the result set to the first 25, and format the result as JSON."
Facebook::Graph also has full support for building privileged applications, so you can see the data as you would if you were logged into Facebook, rather than just the publicly accessible information. I'll be doing another post on that as it's a bit too complex to add to this already too long post.
As you can see it's quite powerful. If your needs are large you won't be able to set aside WWW::Facebook::API yet, but if you want a simpler and faster way to get started with Facebook integration, Facebook::Graph just might be your answer.
I still need to add publishing of content, deleting of content, access to pictures, impersonation, and analytics to have a feature complete API. If anybody is interested in contributing to the module create a fork of the github repository and send me your pull requests.