Facebook Invite Friends for ASP.NETFacebook Invite ASP.NET control is used to send invite requests to friends, to use Facebook application or Facebook Connect web site. To send an invite requests is very useful feature for sharing awareness about Facebook application. It is usually used when users of an application don't want to just share info about application, but they want for their friends to join. Facebook Invite is frequently used in games to invite friends to join game. That is usually rewarded with some points to user who invited them, and it enables him to cooperate with his friends in game too. There are 2 types of Facebook Invite Friends ASP.NET control: the classic one and the small (condensed) one. The classic one is usually bigger in size and it displays pictures of user's friends. Small one contains just a list of friends' names. However, there are properties to set height and width (number of rows and columns) for both of them.
Facebook Invite Friends ClassicFollowing text is describing classic type of Facebook Invite Friends ASP.NET control. Here you can find picture of the control, instructions how to configure it, and code examples. After this section, there is the same section about small type of the control. Picture of the control: Following picture shows screenshot of classic invite friends control with request preview opened. It is created with minimal required setting. Pictures of friends and last names are hidden because of privacy protection.
Facebook Invite Friends classic ASP.NET control has a demo page inside Demo Website that shows how it works. The most important fact is that the Demo website is contained in the package with the library, which is very useful resource for code examples, in both C# and VB.NET, for each control from the library. Look at the Facebook Invite Friends classic demo
ConfigurationConfiguration of the Facebook Invite Friends ASP.NET control is done in ASPX page by setting mandatory and optional properties. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. Following tables contains the list of mandatory and optional properties. First 2 properties are mandatory and if they are not set control will throw an exception on page load. Mandatory Properties:
Property Name
Type
Description
MainTitle
String
Main title of control is text which placed at top of control dialog.
Content
String
Text which is shown in invite request. It is very important to write something attractive to invoke user to accept the request to try a Facebook application or visit a website.
Optional Properties:
Property Name
Type
Description
ActionUrl
String
URL where application is redirected after invite requests are sent. If it is not set, value is taken from web.config key 'AppUrl'.
AcceptUrl
String
When user accept invite request it will be redirected on defined URL. If the property is not set, value is taken from ActionURL property.
AppName
String
Application name displayed on send button and invite request title. If it is not set, value is taken from web.config key 'AppName'.
ShowBorder
Bool
If border has to be shown. Default value is true.
EmailInvite
Bool
If email section has to be shown inside control. The section is not shown if ImportExternalFriends property is set to true. Default value is true.
ImportExternalFriends
Bool
Show dialog for import external friends from email and other services after Facebook friends are selected for invite. Default value is true.
Rows
Int
Number of rows. Default value is 5.
Columns
Int
Number of columns. Default value is 5.
ExcludeFriends
String
Comma separated value string of friend IDs which should not to be in invite list.
ExcludeFriendsList
List
List of friend IDs which should not to be in invite list.
Usage Examples:
Following examples show registration and insertion of Facebook Invite Friends classic ASP.NET control inside ASPX page. The first example shows the control with minimal (only two) mandatory properties set, while the second one shows the control with all properties set. Two properties are excluded from setting in ASPX (ExcludeFriends and ExcludeFriendsList) because they depend on list of user's friends and selection of exclusion, so they cannot be set statically in ASPX. Since both properties have the same purpose, but for different value types, example in the code behind shows just the setting of ExcludeFriendsList from list of user’s friends whose name starts with 'A'. For this purpose, Facebook Graph API method from Facebook C# SDK is used to get the list of user friends.
Minimal properties: <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %> <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteControl.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Facebook Connect Invite Friends Control for ASP.NET</title> <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." /> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <fvk:invite ID="invite1" runat="server" MainTitle = "Facebook Visual Kit" Content = "Facebook Visual Kit is a set of ASP.NET user controls that facilitate ... " /> </asp:Content> All properties: <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %> <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteControl.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Facebook Connect Invite Friends Control for ASP.NET</title> <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." /> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <fvk:invite ID="invite1" runat="server" MainTitle = "Facebook Visual Kit" Content = "Facebook Visual Kit is a set of ASP.NET user controls that facilitate ... " ActionUrl = "http://apps.facebook.com/someapp/Page1.aspx" AcceptUrl = "http://apps.facebook.com/someapp/Page2.aspx" AppName = "My Application Name" Rows = "3" Colums = "3" EmailInvite = "false" ImportExternalFriends = "false" /> </asp:Content> Set excluded friends 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 InviteFriends : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
FacebookApp facebook = new FacebookApp();
if (facebook.Session != null)
{
IList
Set excluded friends 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 InviteFriends
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim facebook As New FacebookApp()
If facebook.Session IsNot Nothing Then
Dim excludedFriends As IList(Of Long) = New List(Of Long)()
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)
excludedFriends.Add(id)
Next
invite1.ExcludeFriendsList = excludedFriends
End If
End If
End Sub
End Class
End Namespace
Facebook Invite Friends CondensedFollowing text is describing small (condensed) type of Facebook Invite ASP.NET control. Here you can find a picture of the control, instructions on how to configure it, list of properties with descriptions, and code examples. Picture of the control: Following picture shows screenshot of small invite friends control with 3 friends selected for invite, and it is created with minimal required setting. Last names of user's friends are hidden because of privacy protection.
Facebook Invite Friends small ASP.NET control has a demo page inside Demo Website that shows how it works. The most important fact is that the Demo website is contained in the package with the library, which is very useful resource for code examples, in both C# and VB.NET, for each control from the library.Look at the Facebook Invite Friends small demo
ConfigurationConfiguration of the Facebook Invite control is done in ASPX page since usually all properties are static. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. Following tables contains the list of mandatory and optional properties. First property is mandatory and it has to be set. If it is not, an exception is thrown on page load. Mandatory Properties:
Property Name
Type
Description
Content
String
Text which is shown in invite request. It is very important to write something attractive to invoke user to accept the request to try an Facebook application or visit website.
Optional Properties:
Property Name
Type
Description
ActionUrl
String
URL where application is redirected after invite requests are sent. If it is not set, value is taken from web.config key 'AppUrl'.
AcceptUrl
String
When user accept invite request it will be redirected on defined URL. If the property is not set, value is taken from ActionURL property.
AppName
String
Application name displayed on send button and invite request title. If it is not set, value is taken from web.config key 'AppName'.
Width
Int
Width of control in pixels. Default value is 300.
UnselectedRows
Int
Number of rows for unselected friends. Default value is 6.
SelectedRows
Int
Number of rows for selected friends. Default value is 5.
ExcludeFriends
String
Comma separated value string of friend IDs which should not to be in invite list.
ExcludeFriendsList
List
List of friend IDs which should not to be in invite list.
Usage Examples:
Following examples show registration and insertion of Facebook Invite Friends condensed ASP.NET control inside ASPX page. The first example shows the control with minimal (only one) mandatory properties set, while the second one show the control with all properties set, except of setting the list of excluded friends. However, an example of this property’s setting is shown for Invite Friends classic control and it is also valid for this control.
Minimal properties: <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %> <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteSmallControl.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Facebook Connect Invite Friends Control for ASP.NET</title> <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." /> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <fvk:invite ID="invite1" runat="server" Content = "This is a content of Invite request." /> </asp:Content> All properties: <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %> <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteSmallControl.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server"> <title>Facebook Connect Invite Friends Control for ASP.NET</title> <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." /> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"> <fvk:invite ID="invite1" runat="server" Content = "This is a content of Invite request. " ActionUrl = "http://apps.facebook.com/someapp/Page1.aspx" AcceptUrl = "http://apps.facebook.com/someapp/Page2.aspx" AppName = "My Application Name" Width = "400" UnselectedRows = "10" SelectedRows = "10" /> </asp:Content> How to get invited friends?After friends are invited, or invitation is canceled ('Skip' button is pressed), Facebook Invite Friends ASP.NET control will make redirect to page defined in ActionUrl property. Inside the code behind this page, it is possible to get invited friends' IDs (empty string if skip is made). Friends’ IDs are sent using HTML GET method. Because of that, it is possible to get them by calling QueryString on current Request object. Following code examples show how to get friends' IDs and how to get friends' names by calling FQL query using Facebook C# SDK. Get Invited friends with C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Facebook;
namespace FVK_Demo
{
public partial class InvitedFriends : System.Web.UI.Page
{
IList<string> friendNames = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
string friendIds = Request.QueryString["ids[]"];
if (friendIds != null)
{
FacebookApp facebook = new FacebookApp();
string query = "select name from user where uid in (" + friendIds + ")";
JsonArray friendsArray = (JsonArray)facebook.Query(query);
foreach (JsonObject f in friendsArray)
{
friendNames.Add((string)f["name"]);
}
}
}
}
}
}
Get Invited friends with VB.NET:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Facebook
Namespace FVK_Demo
Public Partial Class InvitedFriends
Inherits System.Web.UI.Page
Private friendNames As IList(Of String) = New List(Of String)()
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim friendIds As String = Request.QueryString("ids[]")
If friendIds IsNot Nothing Then
Dim facebook As New FacebookApp()
Dim query As String = "select name from user where uid in (" & friendIds & ")"
Dim friendsArray As JsonArray = DirectCast(facebook.Query(query), JsonArray)
For Each f As JsonObject In friendsArray
friendNames.Add(DirectCast(f("name"), String))
Next
End If
End If
End Sub
End Class
End Namespace
|