What are the prerequisites for Facebook stream.publish?

api, facebook, php

Solution

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);

Problem

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

Original source