Alex Mcp
Alex Mcp

Reputation: 19315

What are the prerequisites for Facebook stream.publish?

I'm wondering if someone would help me troubleshoot my test for stream.publish. I thought I had all the right pieces. Here's the code:

<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();


$message = "Will this status show up and allow me to dominate the world?!";
$uid = $user_id;
echo $uid;
$facebook->api_client->stream_publish($message,$uid);

What I'm expecting is my status to change to $message's content. What happens instead is that my UID is echo'd, and then it throws a 500 error. I've allowed publish_stream as well as offline_access (verified in my app settings, via my profile), the the API key hooks this small bit of code to my app. What other pieces do I need to make this simple example work? I'm finding the FB documentation a little hard to put together.

-- The include is the official PHP Facebook library

Upvotes: 4

Views: 26935

Answers (4)

Relaxing In Cyprus
Relaxing In Cyprus

Reputation: 2016

This one works in 2011! I had the same problem. Most of the tuts seem to be out of date thanks to Facebook changes. I eventually found a way that worked and did a quick blog article about it here:

http://facebookanswers.co.uk/?p=214

There's also a screen shot to show you what the result is. Make sure you also see the blog post about authentication though.

Upvotes: 2

Michael
Michael

Reputation: 36

If you are trying to use streamPublish with an iFrame application, here is an awesome step-by-step tutorial that doesn't have to use getAppPermissions:

http://thetechnicalexperience.blogspot.com/2010/02/how-to-use-fbconnectstreampublish.html

Upvotes: 0

Mike Heinz
Mike Heinz

Reputation: 1837

stream_publish() takes more than two arguments:

stream_publish($message, $attachment = null, 
               $action_links = null, $target_id = null, 
               $uid = null)

Where $target_id is the user or page you're publishing to and $uid is the user or page who is doing the publishing - and which defaults to your session id. To be completely explicit about this, I think you need to try

<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

$message = "Will this status show up and allow me to dominate the world?!";

echo $user_id;
$facebook->api_client->stream_publish($message,null,null,$user_id,$user_id);

An alternate form might be:

$app_id = 'xxxxxxx'; 
$facebook->api_client->stream_publish($message,null,null,$user_id,$app_id);

Upvotes: 6

Stepan Mazurov
Stepan Mazurov

Reputation: 1374

Remove the $uid variable as it is not needed for publishing. Refer to this wiki entry for more info

$stream_post_id = $facebook->api_client->stream_publish($message); 
//returns $post_id to use if you want to revert the creation. 

Upvotes: 0

Related Questions