Facebook Stream Publish to Friends for ASP.NETFacebook Stream Publish Friend List control is used to publish stories on the friends' walls simply by selecting a friend from the list and clicking one button. Publishing a story on friend's wall is much more effective if somebody wants to inform this person about something. Story is not only sent to user’s friends, but also to friends of user’s friends. The control enables you to create a list of selected friends from which a user can choose to whose wall he will publish a story. Facebook Stream Publish to Friends is frequently used in Facebook gift applications to leave info about sent gift to friend's wall, and so ensure that he/she will see it. Is it also used in games, for example, to send info about achievements, to send request for something from a friend, how they play the same game, or to send to friend info that user just got something that can be useful to this particular friend. Because of limitation in Facebook API, and also because of Facebook terms and conditions, it is not possible to publish something on multiple friends' walls at once. User has to choose friends one by one from the list, and publish to their walls for each of them separately. The control is available in C# and VB.NET programming languages, as part of Facebook ASP.NET (C# and VB.NET) Control library.
![]() Usage Examples:
Following example shows usage of Facebook Stream Publish Friends List 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="streampublishfriends" Src="~/FVK/StreamPublishFriendList.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:streampublishfriends ID="streampublish1" runat="server" OnPublishCalled="OnPublishStory" OnConfirmCalled="OnConfirmStory" BoxText = "Make sure to inform your friend about Facebook Visual Kit by sending a story on his wall" MainImageUrl = "logo.png" Title = "Publish to friends' wall" PostBtnTitle = "Post" HideBtnTitle = "Hide" 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#:
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 friend list
IList
Code behind in VB.NET:
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 friend list
Dim friends As IList(Of FriendData) = New List(Of FriendData)()
Dim count As Integer = 0
Dim accessToken As String = FvkAuth.AccessToken
Dim facebook = New FacebookClient(accessToken)
Dim friendsData As JsonObject = DirectCast(facebook.Api("me/friends"), JsonObject)
Dim friendsList As JsonArray = DirectCast(friendsData("data"), JsonArray)
For Each f As JsonObject In friendsList
Dim id As Long = Int64.Parse(DirectCast(f("id"), String))
Dim name As String = DirectCast(f("name"), String)
friends.Add(New FriendData(id, name))
count += 1
If count = 4 Then
Exit For
End If
Next
streampublish1.Friends = friends
End If
End Sub
End Class
End Namespace
ConfigurationConfiguration of the Facebook Stream Publish Friend List ASP.NET control is done in ASPX page by setting properties and optional event handlers, and, as it is written in text above, the configuration is very similar to one in Facebook Stream Publish Popup ASP.NET control. 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, there are mandatory and optional properties, as they are shown in following 2 tables. Mandatory properties and first 2 from optional properties are only addition in configuration in comparison to Stream Publish Popup control. All about media types, action links, and story properties can be found in tutorial about Facebook Stream Publish Popup ASP.NET control. Mandatory Properties:
Property Name
Type
Description
BoxText
String
Text inside the box. This text has to be attractive enough to motivate user to publish on friends' wall.
MainImageUrl
String
Url of the image inside the box for selecting friends. It is not connected with the image that you might want to publish as content.
Title
String
Title of the box (text on top blue border).
Friends
IList
List of FriendData objects which have to be in list inside the box.
Optional Properties:
Property Name
Type
Description
PostBtnTitle
String
Title of post button. Default value is 'Post'.
HideBtnTitle
String
Title of hide button. Default value is 'Hide'.
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 permissions 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 i.e. 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 written 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).
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.
|