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.

This class is a member of Facebook Connect PHP Toolkit. To see all classes from the toolkit, please look at the Facebook Connect Graph API classes.


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.

facebook stream publish


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>



Facebook Stream Publish PHP class has a demo page inside Demo Website where it can be seen how it works. The most important fact is that the Demo website is contained in package with Facebook Connect PHP Toolkit which is very useful resource of code examples for each control from the toolkit. Look at Facebook Stream Publish Demo page.


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.

facebook stream publish php
Method Name
Type
Description
facebook stream publish php
SetCommandType
String
Function sets the type of the command control. Allowed values are 'link', 'button', 'image' and 'auto'. Default value is 'button'.
facebook stream publish php
SetCommandText
String
Function sets the title of a publish button/link. Default value is 'Publish'.
facebook stream publish php
SetName
String
Function sets the name of the story.
facebook stream publish php
SetNameUrl
String
Function sets the URL of the name. If it's set, the name of story is linked.
facebook stream publish php
SetCaption
String
Function sets the caption of the story.
facebook stream publish php
SetDescription
String
Function sets the description of the story.
facebook stream publish php
SetUserMessage
String
Function sets predefined user message.
facebook stream publish php
SetFriendId
String
Function sets the friend ID. If it's set, the story is published on the friend's wall.
facebook stream publish php
SetPageId
String
Function sets the Facebook Page ID. If it's set, the story is published on the Facebook Page.
facebook stream publish php
SetOnPublishJavaScript
String
Function sets the JavaScript code to be executed after the story is published.
facebook stream publish php
SetOnPublishSubmitForm
String
Function sets the form ID to be submitted after the story is published.
facebook stream publish php
SetCssStyle
String
Function sets the CSS style of the button/link.
facebook stream publish php
SetCssClass
String
Function sets the CSS class of the button/link.
facebook stream publish php
SetMedia
MediaType
Function sets the instance of MediaType. Allowed types are ImageMedia, VideoMedia, Mp3Media and FlashMedia.
facebook stream publish php
AddActionLink
ActionLink
Function adds new instance of ActionLink in action links list. For details look at ActionLinks section.
facebook stream publish php
AddProperty
Property
Function adds new instance of Property in property list. For details look at Properties section.
facebook extended permissions php
SetImage
String
Function sets the image of the button. Image type is set automatically.


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

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
imageUrl
String
URL of image file.
facebook stream publish php
destUrl
String
Destination URL when image is clicked.


VideoMedia PHP Class

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
videoUrl
String
URL of video file.
facebook stream publish php
imageUrl
String
URL of preview image file.
facebook stream publish php
destinationUrl
String
Destination URL when video is clicked.
facebook stream publish php
videoTitle
String
Video title


Mp3Media PHP Class

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
mp3Url
String
URL of mp3 file.
facebook stream publish php
title
String
Song title
facebook stream publish php
artist
String
Artist name.
facebook stream publish php
album
String
Album name


FlashMedia PHP Class

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
swfUrl
String
URL of SWF file.
facebook stream publish php
imageUrl
String
URL of preview image file.
facebook stream publish php
width
String
Width in pixels of preview.
facebook stream publish php
height
String
Height in pixels of preview.
facebook stream publish php
expandedWidth
String
Width in pixels of flash after preview is clicked.
facebook stream publish php
expandedHeight
String
Height in pixels of flash after preview is clicked.


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

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
text
String
Anchor text of the link.
facebook stream publish php
url
String
Destination of the link.


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

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
name
String
Name of the property.
facebook stream publish php
url
String
Text of the property.

LinkedPropery Class

facebook stream publish php
Parameter Name
Type
Description
facebook stream publish php
name
String
Name of the property.
facebook stream publish php
url
String
Anchor text of the property.
facebook stream publish php
name
String
Destination URL of the property.