Facebook Stream Publish PHP class is used to publish stories on user’s profile, friends' profiles or the Facebook page (if the user is admin of that page). There are 4 possible media types available for publishing: image, video, flash and MP3. It is also possible to define JavaScript code which will be executed, and form id which will be submitted, after the story is successfully published.
Stream Publish Popup Image
Following image shows Facebook Stream Publish Popup window which is opened after the button/link for publishing is pressed. It contains story name, linked with URL of website. That is great way to create more links to your website. It also contains caption, with name of user who publishes it, and description. For media types, an image is set.
PHP Example
The example shows how to configure Facebook Stream Publish class whose popup is shown on picture above. The PHP code also shows how to set JavaScript which will be executed after the story is successfully published. For this example, it is chosen to execute just the alert command. The example shows the code of whole page, but important content is highlighted: required includes and initialization for any page with brown color, and working with Facebook Stream Publish PHP class with blue color.
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> <head> <title>Facebook Stream Publish PHP example</title> </head> <body> <?php require_once 'facebook.php'; require_once 'faceconn/faceconn.php'; UseGraphAPI(); $publish = new StreamPublish(); $publish->SetName("Story Name"); $publish->SetNameUrl("http://faceconn.com"); $publish->SetCaption("{*actor*} publish this story:"); $publish->SetDescription("This is a description of the story"); $publish->SetOnPublishJavaScript("alert('Published')"); $publish->SetMedia(new ImageMedia("http://faceconn.com/img/cat.png", "http://faceconn.com")); $publish->AddPropery(new Property("Product Name", "Faceconn Toolkit")); $publish->AddActionLink(new ActionLink("Faceconn", "http://faceconn.com")); $publish->Render(); ?> </body> </html>
Configuration
Configuration of the Facebook Stream Publish PHP class is done through calls of the setter methods, which in turn set the private properties. For Facebook Stream Publish PHP class, there are no required properties to set. All you have to do is to create new instance of the class and call Render() method. All properties from the list below are optional.
Media Types
All media types implement the same interface called MediaType. The interface provides a method to create JSON string which is included in JavaScript for stream publishing. However, all of this is hidden from the user and it is enough to provide media object to SetMedia method. All media objects can be created with parameterized constructor. Here is the list of all media type classes and constructor parameters:
ImageMedia PHP Class
VideoMedia PHP Class
Mp3Media PHP Class
FlashMedia PHP Class
Action Links
Action Links allow additional actions on published stories by providing aditional links. They can not be seen on publish dialog, but only on wall when story is published. The interface provides a method to create JSON string which is included in JavaScript for stream publishing. However, all of this is hidden from the user and it is enough to add ActionLink object by using AddActionLink method. Action links objects can be created with parametrized constructor. Here is the table of constructor parameters:
ActionLink Class
Properties
Properties are name-text and name-link pairs, positioned bellow story description. The interface provides a method to create JSON string which is included in JavaScript for stream publishing. However, all of this is hidden from the user and it is enough to add Property or LinkedProperty object by using AddProperty method. Property objects can be created with parametrized constructor. Here are tables of constructor parameters for both property classes:
Propery Class
LinkedPropery Class

