Facebook Stream Publish for ASP.NETFacebook Stream Publish Pop-up is used to publish stories on the user wall, friends' walls, or on the page wall (if the user is admin). This control is a wrapper around Graph API JavaScript method FB.UI(), and it hides all complexities (like JSON conversion, media attachments packaging, etc.) from the user. The control uses configuration of the stream publish story, by exposing pure .NET objects with properties that the user can set to his liking. Events are also provided, for checking whether publish dialog is opened, and if the story is published. The control is available in C# and VB.NET programming languages, as part of Facebook ASP.NET (C# and VB.NET) Control library. Please also look at similar ASP.NET control at Facebook Stream Publish Friend List control.
![]() Usage Examples:
Following example shows usage of Facebook Stream Publish ASP.NET control, from registration and insertion in ASPX file, to implementation of an event handler and setting of dynamic properties in the code behind. Implementation is given in C# and VB.NET programming languages.
Integration in ASPX file: <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.StreamPublish" %> <%@ Register TagPrefix="fvk" TagName="streampublishpopup" Src="~/FVK/StreamPublishPopup.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Facebook Stream Publish Control for ASP.NET</title> <meta name="description" content="ASP.NET Stream Publish popup control for Facebook Connect web sites." /> <script type="text/javascript" src="/FVK/JavaScript/JSON.js"></script> <script type="text/javascript" src="/FVK/JavaScript/StreamPublishPopup.js"</script> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <fvk:streampublishpopup ID="streampublish1" runat="server" OnPublishCalled="OnPublishStory" OnConfirmCalled="OnConfirmStory" Name = "Facebook Visual Kit for ASP.NET" Href = "http://vatlab.com" Caption = "{*actor*} is trying Facebook Visual Kit Demo." Description = "Facebook Visual Kit is a set of ASP.NET user controls ..." UserMessage = "Try this ASP.NET library for Facebook development !!" /> </asp:Content> Code behind in C#: Following code shows the code behind if you want to set image media, properties and action links in C# programming language. ActorId and TargetId are not set because story has to be published on selected user’s wall.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
using FVK;
namespace FVK_Demo
{
public partial class StreamPublish : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// set image media
streampublish1.Media = new ImageData("logo.png", "url1");
// set properties
List
Code behind in VB.NET: Following code shows the code behind if you want to set image media, properties and action links in VB.NET programming language. ActorId and TargetId are not set because story has to be published on selected user’s wall.
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Facebook
Imports FVK
Namespace FVK_Demo
Public Partial Class StreamPublish
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
' set image media
streampublish1.Media = New ImageData("http://vatlab.com/.../logo.png", "url1")
' set properties
Dim properties As New List(Of IJSONSerialize)()
properties.Add(New PropertyData("Text Property", "This is property description"))
properties.Add(New LinkedPropertyData("Link Property", "This is property link", "url2"))
streampublish1.Properties = properties
' set action links
Dim linkList As New List(Of LinkData)()
linkList.Add(New LinkData("action link", "url3"))
linkList.Add(New LinkData("action link2", "url4"))
streampublish1.ActionLinkList = linkList
End If
End Sub
Protected Sub OnPublishStory(sender As Object, e As EventArgs)
' stream publish popup dialog opened
End Sub
Protected Sub OnConfirmStory(sender As Object, e As EventArgs)
If streampublish1.ReturnedPostId IsNot Nothing Then
'Story is published
Else
' Story is not published
End If
End Sub
End Class
End Namespace
ConfigurationConfiguration of the Facebook Stream Publish ASP.NET control is done in ASPX page by setting properties and optional event handlers. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. If event handlers are used, there should be methods in the code behind to execute additional code after event handlers are executed. For Facebook Stream Publish ASP.NET control, all properties are optional. It is possible to create a story which contains only user comments. However, Stream Publish is frequently used to publish some pictures, videos and interesting stories. The control is very frequently used in Facebook quiz and gift applications, for example, to publish results of a quiz, or to publish that user is sending a gift to somebody. Because of that, for Stream Publish ASP.NET control, configuration of properties is usually done in the code behind, to depend on user actions. It is also possible to make a mix, with properties which are static to ASPX file, and dynamic properties which depend on user action in the code behind. For example, static properties can be Name and Href, while dynamic properties can be Description and Media. Definition of event handlers is always done in ASPX file, since it does not depend on user action. Properties:
Property Name
Type
Description
CommandType
String
Can be set to 'link', 'button', or 'auto_open'. This means permissions popup dialog is opened by: pressing a link, button, or automatically on page load. Default value is 'button'.
CommandTitle
String
Text of stream publish button or link. If 'auto_open' command type is used, this parameter is ignored. Default value is 'Publish'.
Name
String
Name of the story. If this property is linked (if Href property is set), it is important to put relevant keywords inside name to raise search engine ranking of website or Facebook application.
Href
String
URL of the content inside website or Facebook application where story is pointing.
Caption
String
Caption of the story (first line below title). It is possible to include {*actor*} tag to write name of the user who published the story.
Description
String
Description of the story. The main text of the story. It has no limitation in length.
MessagePrompt
String
Message prompt is text displayed on top border of stream publish dialog.
UserMessage
String
Predefined user message. If user publishes a story, this text will be seen in news feed as he writes some comment about the story.
Media
IJsonSerialize
One of media objects (ImageData, VideoData, FlashData, or Mp3Data). Details about initializing media types can be found in following text.
MediaList
IList
List of media (IJsonSerialize) objects. Facebook currently supports only Image media type.
Properties
IList
List of PropertyData and LinkedPropertyData objects.
ActionLinkList
IList
List of action links (LinkData objects).
TargetId
String
Set to Facebook user id of a friend to publish on the friends' wall. ActorId must not be set.
ActorId
String
Set to page id to publish on Facebook page wall (only if user is admin of the page). TargetId must not be set.
Event Handlers:
Event Name
Description
OnPublishCalled
Has to be set to name of protected method that is implemented inside the code behind, and which will be called after Facebook Stream publish dialog is opened.
OnConfirmStory
Has to be set to name of protected method that is implemented inside the code behind, and which will be called after user confirms publishing of the story.
Media TypesConfiguration of media types is done by creating new object with parameters in class constructor. It is also possible to create objects with default constructor and then set all properties of the objects. In following text, there are tables with descriptions of all constructor parameters and properties inside constructors, for each media type. Names of the properties and the constructor parameters are the same. ImageData Class:
Property Name
Type
Description
ImageUrl
String
URL of image file
DestUrl
String
URL where user is redirected after a click on the image.
VideoData Class:
Property Name
Type
Description
VideoSrc
String
URL of video file
PreviewImg
String
URL of preview image.
VideoLink
String
Destination URL when video is clicked.
VideoTitle
String
Title of the video.
VideoLink
String
Destination URL when video is clicked.
VideoTitle
String
Title of the video.
MP3Data Class:
Property Name
Type
Description
Src
String
URL of mp3 file
Title
String
Song Title
Artist
String
Artist name
Album
String
Album name
FlashData Class:
Property Name
Type
Description
SwfSrc
String
URL of SWF file
ImgSrc
String
URL of preview image file.
Width
Int
Width of preview
Height
Int
Height of preview
ExpandedWidth
Int
Expanded Width
ExpandedHeight
Int
Expanded Height
Action LinksAction links are links which are located at the bottom of stream post. They are not visible in Facebook Stream Publish dialog, but only when story is published on user’s or Facebook page wall. They are used to provide more actions for your post. Action links are set by setting a list of LinkData objects to ActionLinks property. There is an example of this in Usage Example section. Following table shows properties (constructor parameters) of LinkData class. LinkData Class:
Property Name
Type
Description
Text
String
Anchor text of the link
Href
String
Destination of the link.
PropertiesProperties are name-value pairs, positioned bellow story description. Value is separated from name with one space character. On the picture above, you can see how it looks. There are 2 types of properties: text property and linked property. Linked property creates link (instead of plain text) with defined target URL. Tables bellow show properties (constructor parameters) of PropertyData (text property) and LinkedPropertyData classes. PropertyData Class:
Property Name
Type
Description
Name
String
Name of property
Text
String
Text value of property.
LinkedPropertyData Class:
Property Name
Type
Description
Name
String
Name of property
Text
String
Anchor text of property.
Href
String
Destination URL of property
|