Making WWW::Facebook::API Facebook Connect Ready

FacebookI’m going to get geeky on you here again.  I’ve been working on a few things with SocialToo to enable Facebook Connect on the site – more on that to come.  What I’ve been surprised by though is that this long after the launch of Facebook Connect the main Perl libraries for Facebook, WWW::Facebook::API, still do not support Facebook Connect.  The main difference between making API calls from a native Facebook app and a third-party Facebook Connect app is that in the native app, you verify the signature via the URI parameters, via parameters that begin with “fb_sig_”.  In Facebook Connect, those variables are set in Cookies by the Facebook Client-side Javascript libraries, and begin with your applications API key, so they’d start something like “(api key)_”, and come from the cookies instead of the URI.  You can read more about that here.

So for full compatibility in your preferred Facebook API libraries, both the URI parameters have to be checked along with the Cookies in the event the developer is trying to connect from a third-party website.  In the PHP libraries this is already done for you.  Surprisingly, Perl has not yet implemented this.

So I got to work on it, and through a couple simple lines of code added to WWW::Facebook::API::Canvas I was able to make get_fb_params check your cookies when the URI parameters are not presence.  I’ve submitted the patch to the library’s owner, Clayton Scott, but in case you want to integrate it sooner you can apply it to the 0.4.14 version of Canvas.pm by downloading this patch.

I hope you’re able to get as much out of this as I am – please let me know if you see any potential bugs with the changes.

Advertisements

16 thoughts on “Making WWW::Facebook::API Facebook Connect Ready

  1. Great news! Ive installed the API through CPAN, any pointers for how to correctly patch it would be much appreciated. Thanks

    Like

  2. Marcus, just run patch on the linked file above against
    WWW::Facebook::API::Canvas and you're set. Clayton's recovering from having
    a baby but it should be in his code shortly. Also, I have a
    Catalyst::Authentication::Credential::Facebook module I'm about to publish
    as well if you use Catalyst and need a simple single sign-on solution that
    uses Facebook Connect. (I have one for Twitter OAuth as well that will go
    out at the same time, along with hopefully FriendFeed)

    Like

  3. Hey Jesse. Thanks for the patch. Would you mind giving some example code that is supposed to work after the patch? I've verified that cookies are being set after logging in using Connect's javascript, however when I go to my PERL script after logging in, I get just get errors. I'm using the standard constructor, but something like my

    $reponse = $client->canvas->get_user( $q );

    produces “Can't call method “value” without a package or object reference at /usr/lib/perl5/site_perl/5.8.8/WWW/Facebook/API/Canvas.pm line 35″

    I haven't written a Facebook app in a long time, and this is my first Connect app, so I know it is something stupid, but I can't make the leap from standard WWW::Facebook::API to the correct order of things after the Connect patch.

    Thanks again!

    Like

  4. Hey Jesse. Here's what I've got.

    use WWW::Facebook::API;

    my $q = CGI->new;

    my $client = WWW::Facebook::API->new(
    desktop => 0,
    api_key => 'my_key',
    secret => 'my_secret',
    debug => 1
    );

    Like

  5. Thanks for this article Jesse, it helped clarify things for me.

    However, I have exactly the same problem as johngalt2.

    I've patched WWW::Facebook::API as indicated, and my test Facebook Connect app fails as above.

    I would love to see some sample Perl code that does *anything* with Facebook Connect.

    (I have Facebook Connect samples in plain html/javascript working OK).

    Cheers,

    Simon

    Like

  6. Hey Jesse. Here's what I've got.

    use WWW::Facebook::API;

    my $q = CGI->new;

    my $client = WWW::Facebook::API->new(
    desktop => 0,
    api_key => 'my_key',
    secret => 'my_secret',
    debug => 1
    );

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s