tags:

views:

15445

answers:

8

Hi, 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

A: 

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.
smazurov
In my script then how will it know to which user's account to publish the message?
Alex Mcp
call like this $facebook->api_client->stream_publish($message, $attachment, $actionlinks);and it will publish to all your friends wall.
Gaurav Sharma
+6  A: 

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);
Mike Heinz
My issue was that all the parameters were listed as optional, so I only included what I thought I needed, without thinking that the order of them dictated what they meant (IE, to use placeholders to answer ALL the available parameters) Thanks a lot for helping me with this.
Alex Mcp
A: 

Here is a Simple 5 step code to post on a wall without login to application. http://blog.theunical.com/facebook-integration/5-steps-to-publish-on-a-facebook-wall-using-php/

Steven
The link above appears to be down.
ftrotter
A: 

i followed that 5 step guide, but it requires user to type urls and copy paste codes to post, is there any way to automatize it?

jandj
A: 

I'm using the code below:

<?php
$facebookinclude = '../facebook-platform/php/facebook.php';

$appid = 'XXXXXX';

require_once($facebookinclude);

$facebook = new Facebook('XXXXXX', 'XXXXXX');

$user_id = $facebook->require_login();

$message = "Test Message";

echo $user_id;

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

?>

But I also get a 500 error, right after the user id is echoed...

I've also tried this:

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

and this

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

but with the same result...

Is there any way to get a more meaningful error message? Can anyone spot what is wrong with my code...?

A: 

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

Michael
A: 

i'm using FBML and i want to use stream.publish to a specific page in my program. one of the stream.publish parameters is target_id which i can use page_id for this. how can i get the specific page_id ?

sharon
A: 

isn't there complete working example about stream publishing ? everybody says something .. please give me a working example in php ..

renegade77