tags:

views:

192

answers:

1

Hello,

I have a web application that allows a user to publish a small blurb when one of their articles goes live on their site. Right now I am able to post to the user's wall using a session_key I saved in a table but I can't publish the same link on a fan page (I have the rights and IDs of the pages I need).

Essentially I want the functionality of: http://wiki.developers.facebook.com/index.php/Links.post but for a page instead. So far all I can find utilizes the steam.publish function which isn't quite the same thing.

I'm hoping that there's a hidden parameter (like a target_id) in the link.post function that I've missed (since the facebook wiki is horrible).

Any help is appreciated :) If there isn't a function maybe someone could help me use the parameters of stream.publish to have the content of a post look the same?

A: 

Well I couldn't find a way to use the link_post() function to post to a fanpage so I decided to shape the stream.publish result in a way that it would look the same. I had to do a lot of dancing around the variables to get the same effect but it worked. In this case I had to grab the "description" metatag, the first image in the page's content, and the page's title.

I hope this can help someone out:

$title = 'Title of the article, or the title of your webpage';
$message = 'Caption that will go with the link, from the user';
$description = 'I put what would have been in the description metatag, which is what the post link seems to grab';
$fb_thumbnail = ''; // a link to the first image in your article
$target_id = 'XXXXXX'; // the id of the fan page you want to post to

$attachment = array( 'name' => $title,
                'href' => 'http://'.$url,
                'description' => $description,
                'media' => array(array('type' => 'image',
                                'src' => $fb_thumbnail,
                                'href' => 'http://'.$url))); // I would get an error with the HREF but that's because I wasn't including the "http://" bit in the link

                $attachment = json_encode($attachment);

                $facebook->api_client->stream_publish($message, $attachment,"",$target_id);
Gazillion