Using Perl WWW::Facebook::API to Publish To Facebook Newsfeed

Posted by Russell C. on Stack Overflow See other posts from Stack Overflow or by Russell C.
Published on 2010-04-16T17:25:42Z Indexed on 2010/04/16 20:23 UTC
Read the original article Hit count: 1371

We use Facebook Connect on our site in conjunction with the WWW::Facebook::API CPAN module to publish to our users newsfeed when requested by the user.

So far we've been able to successfully update the user's status using the following code:

use WWW::Facebook::API;
my $facebook = WWW::Facebook::API->new(
    desktop => 0,
    api_key => $fb_api_key,
    secret => $fb_secret,
 session_key => $query->cookie($fb_api_key.'_session_key'),
 session_expires => $query->cookie($fb_api_key.'_expires'),
 session_uid => $query->cookie($fb_api_key.'_user')
);

my $response = $facebook->stream->publish(
 message => qq|Test status message|,
);

However, when we try to update the code above so we can publish newsfeed stories that include attachments and action links as specified in the Facebook API documentation for Stream.Publish, we have tried about 100 different ways without any success.

According to the CPAN documentation all we should have to do is update our code to something like the following and pass the attachments & action links appropriately which doesn't seem to work:

my $response = $facebook->stream->publish(
 message => qq|Test status message|,
    attachment => $json,
    action_links => [@links],
);

For example, we are passing the above arguments as follows:

$json = qq|{ 'name': 'i\'m bursting with joy', 'href': ' http://bit.ly/187gO1', 'caption': '{*actor*} rated the lolcat 5 stars', 'description': 'a funny looking cat', 'properties': { 'category': { 'text': 'humor', 'href': 'http://bit.ly/KYbaN'}, 'ratings': '5 stars' }, 'media': [{ 'type': 'image', 'src': 'http://icanhascheezburger.files.wordpress.com/2009/03/funny-pictures-your-cat-is-bursting-with-joy1.jpg', 'href': 'http://bit.ly/187gO1'}] }|;
@links = ["{'text':'Link 1', 'href':'http://www.link1.com'}","{'text':'Link 2', 'href':'http://www.link2.com'}"];

The above, nor any of the other representations we tried seem to work. I'm hoping some other perl developer out there has this working and can explain how to create the attachment and action_links variables appropriately in Perl for posting to the Facebook news feed through WWW::Facebook::API.

Thanks in advance for your help!

© Stack Overflow or respective owner

Related posts about perl

Related posts about facebook