I’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.
Discover more from Stay N Alive
Subscribe to get the latest posts sent to your email.
Great news! Ive installed the API through CPAN, any pointers for how to correctly patch it would be much appreciated. Thanks
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)
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!
John, can you provide more information? What is $q? How do you set up your
$client? What request libraries are you using? CGI? Catalyst?
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
);
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
Is it in WWW-Facebook-API-0.4.16 ?
Yes, I believe it's been merged into the latest WWW::Facebook::API now so
you don't have to patch it any more.
Is it in WWW-Facebook-API-0.4.16 ?
Yes, I believe it's been merged into the latest WWW::Facebook::API now so
you don't have to patch it any more.
Thanks for sharing this
It looks good,I have learn a recruit!
Recently,I found an excellent online store, the XX are completely various, good quality and cheap price,it’s worth buying! http://www.grave-yards.com/
It looks good,I have learn a recruit!
Recently,I found an excellent online store, the XX are completely various, good quality and cheap price,it’s worth buying! http://www.grave-yards.com/
It looks good,I have learn a recruit!
Recently,I found an excellent online store, the XX are completely various, good quality and cheap price,it’s worth buying! http://www.grave-yards.com/
Yes, I believe it's been merged into the latest WWW::Facebook::API now so
you don't have to patch it any more.
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
);