Documente Academic
Documente Profesional
Documente Cultură
Toolkitv1.2
DevelopedforMicrosoftByClarityConsultingInc.www.claritycon.com
TableOfContents
LeveragingtheFacebookAPIin5minutes..........................................................................................4
1.1
DesktopDevelopment..................................................................................................................4
1.2
WebDevelopment........................................................................................................................7
1.3
IFrameCanvasDevelopment......................................................................................................12
1.4
FBMLCanvasDevelopment........................................................................................................13
1.5
AJAXinIFrameCanvas................................................................................................................15
1.6
SilverlightinIFrameCanvas........................................................................................................17
Prerequisites.....................................................................................................................................20
Introduction........................................................................................................................................20
Overview.............................................................................................................................................21
4.1
FacebookAPIOverview..............................................................................................................21
4.2
UsingtheFacebookServicetoAccesstheAPI.............................................................................21
4.2.1
InfiniteSessions..................................................................................................................21
4.3
FacebookDesktopDevelopment................................................................................................22
4.4
FacebookWebDevelopment......................................................................................................22
4.5
FacebookCanvasDevelopment..................................................................................................23
4.6
UsingLINQ...................................................................................................................................24
DetailedClassDesign.........................................................................................................................24
5.1
Facebook.Components...............................................................................................................24
5.1.1
5.2
FacebookServiceClass........................................................................................................24
FacebookDataObjects...............................................................................................................47
5.2.1
AlbumClass.........................................................................................................................47
5.2.2
PhotoClass..........................................................................................................................49
5.2.3
FacebookEventClass...........................................................................................................51
5.2.4
GroupClass.........................................................................................................................53
5.2.5
GroupUserClass..................................................................................................................56
5.2.6
UserClass............................................................................................................................56
5.2.7
SchoolHistoryClass.............................................................................................................62
5.2.8
HighSchoolClass.................................................................................................................62
5.2.9
HigherEducationClass.........................................................................................................63
5.2.10
NetworkClass.....................................................................................................................63
5.2.11
LocationClass......................................................................................................................64
5.2.12
WorkClass...........................................................................................................................65
CodeSnippets.....................................................................................................................................65
6.1
WindowsForm:ApplicationSetup.............................................................................................65
6.2
WindowsForm:RetrievingFriends.............................................................................................66
6.3
WindowsForm:UtilizingtheFriendListControl.........................................................................66
6.4
WindowsForm:HookingaFriendListControltoaProfileControl.............................................67
6.5
WebApplication:AuthenticationProcess..................................................................................67
ReleaseNotes:............................................................................................................................................70
Version1.1:.............................................................................................................................................70
Version1.2:.............................................................................................................................................70
1 LeveragingtheFacebookAPIin5minutes
1.1 DesktopDevelopment
SatisfyPrerequisitesdescribedbelow
StartanewWindowsapplicationproject
o FileNewProject
o WindowsApplication
Visual C#
Visual Basic
AddtheFacebookServicecomponentfromthetoolboxtotheFormscomponenttray
ProvidetheAPIKeyandSecretvalues
DragaFriendListfromthetoolboxontothedesignsurfacefortheform
HookuptheformLoadEvent
o FindLoadintheEventlistinthepropertywindow,typeForm_Load.PressEnter.
InthegeneratedForm_Loadmethod,settheFriendspropertyoftheFriendListcontroltothe
CollectionreturnedbycallingtheGetFriendsmethodoftheFacebookService.Asshownhere:
Visual C#
private void Form_Load(object sender, EventArgs e)
{
friendList1.Friends = FacebookService1.GetFriends();
}
VisualBasic
Private Overloads Sub OnLoad()
friendList1.Friends = FacebookService1.GetFriends()
End Sub
PressF5toruntheapplication
1.2 WebDevelopment
SatisfyPrerequisitesdescribedbelow
InVisualWebDeveloper2005Expressedition
o FileNewWebSite
Visual C#
Visual Basic
SwitchtoDesignViewofDefault.aspx
OnDefault.aspx,dragafriendlistfromthetoolbox
AddthefollowingcodetotheDefault.aspx
ConfiguretheAPIkeyandsecret
Visual C#
public partial class _Default : Page
{
Facebook.Components.FacebookService _fbService = new
Facebook.Components.FacebookService();
SettheIsDesktopApplicationpropertyoftheFacebookServicecomponent
Visual C#
_fbService.IsDesktopApplication = false;
Visual Basic
_fbService.IsDesktopApplication = False
CheckifwehavealreadystoredtheFacebooksessioninformationoriftheauth_tokenisinthe
queryparams.WewillstorewhatweknowaboutthecurrentusersFacebookSessionina
serversidevariable.Wewillthencheckthatvariabletoseeifwealreadyhaveestablisheda
Facebooksessiononbehalfofthecurrentuser.
Visual C#
string sessionKey = Session["Facebook_session_key"] as String;
string userId = Session["Facebook_userId"] as String;
// When the user uses the Facebook login page, the redirect back here
will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
Visual Basic
Dim sessionKey As String =
TryCast(Session("Facebook_session_key"), String)
Dim userId As String = TryCast(Session("Facebook_userId"),
String)
' When the user uses the Facebook login page, the redirect back
here will will have the auth_token in the query params
Dim authToken As String = Request.QueryString("auth_token")
Ifwehaveanestablishedsession,setitintoourinstanceoftheservice
Visual C#
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.UserId = userId;
}
Visual Basic
' We have already established a session on behalf of this user
If (Not String.IsNullOrEmpty(sessionKey)) Then
_fbService.SessionKey = sessionKey
_fbService.UserId = userId
Ifnot,checkifwehavetheauth_tokeninthequeryparams.Ifwedo,itmeanswejustgot
calledfromtheFacebookloginpage.
Visual C#
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["Facebook_session_key"] = _fbService.SessionKey;
Session["Facebook_userId"] = _fbService.UserId;
Session["Facebook_session_expires"] = _fbService.SessionExpires;
}
Visual Basic
' This will be executed when Facebook login redirects to our page
ElseIf (Not String.IsNullOrEmpty(authToken)) Then
_fbService.CreateSession(authToken)
Session("Facebook_session_key") = _fbService.SessionKey
Session("Facebook_userId") = _fbService.UserId
Session("Facebook_session_expires") =
_fbService.SessionExpires
Ifneither,weneedtoredirecttheusertotheFacebookhostedloginpage
Visual C#
else
{
Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" +
_fbService.ApplicationKey + @"&v=1.0");
}
Visual Basic
Else
Response.Redirect("http://www.Facebook.com/login.php?api_key=" &
_fbService.ApplicationKey & "&v=1.0")
End If
Setthefriendspropertyofthefriendlist
Visual C#
if (!IsPostBack)
{
// Use the FacebookService Component to populate Friends
MyFriendList.Friends = _fbService.GetFriends();
}
Visual Basic
If (Not IsPostBack) Then
' Use the FacebookService Component to populate Friends
MyFriendList.Friends = _fbService.GetFriends()
End If
1.3 IFrameCanvasDevelopment
OnetypeofcanvaspagesupportedbytheFacebookplatformistheIFramecanvas.Withthistypeof
canvaspage,facebookwillhostaniframecontainingthecontentforyouapplication.Thistypeof
canvascannottakeadvantageofthefeaturesoffbml,butallowsformoretraditionalwebdevelopment
practicesforfacebookapplications.
HowtostartyourIFramecanvasapplicationusingtheFacebookDeveloperToolkit.
Requestanewdeveloperapikeyfromhttp://www.facebook.com/developers/
Configurethefollowingfields.Thevaluesherearethevaluesusedbythesample,youcan
replacewithyourownvalues.
o CallbackURL:http://facebook.claritycon.com/IFrame/
o CanvasPageURL:aspnetcanvasiframe
o UseIFRAME:true;UseFBML:false
o ApplicationType:Website
o Canyourapplicationbeaddedonfacebook:yes
o PostAddURL:http://apps.facebook.com/aspnetcanvasiframe(sameascanvaspage)
o DefaultProfileBox:Wide
o SideNavURL:http://apps.facebook.com/aspnetcanvasiframe(sameascanvaspage)
Createnewasp.netwebsiteinVisualStudio
AddreferencetoFacebook.dll
AddreferencetoFacebook.WebControls.dll
Updatecodebehind(Default.aspx.cs)onDefault.aspxtosubclass
Facebook.WebControls.CanvasIFrameBasePage
Visual C#
using Facebook;
using Facebook.WebControls;
public partial class _Default : CanvasIFrameBasePage
{
Visual Basic
Imports Facebook
Imports Facebook.WebControls
Public Partial Class _Default
Inherits CanvasIFrameBasePage
AddcodetosetAPIkey,secret(Makesuretouseyourownapikeyandsecretacquiredduring
above)
Addcodetocallbase.Page_Loaded
Visual C#
private const string FACEBOOK_API_KEY = "YOURAPIKEYHERE";
private const string FACEBOOK_SECRET = "YOURSECRETHERE";
new protected void Page_Load(object sender, EventArgs e)
{
base.Api = FACEBOOK_API_KEY;
base.Secret = FACEBOOK_SECRET;
base.Page_Load(sender, e);
Visual Basic
Private Const FACEBOOK_API_KEY As String = "YOURAPIKEYHERE"
Private Const FACEBOOK_SECRET As String = "YOURSECRETHERE"
Shadows Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs)
MyBase.Api = FACEBOOK_API_KEY
MyBase.Secret = FACEBOOK_SECRET
MyBase.Page_Load(sender, e)
AddcodetouseFacebookServicetoinvokeAPIcallsonbehalfoftheloggedinuser.
Visual C#
if (!IsPostBack)
{
// Use the FacebookService Component to populate Friends
Facebook.Entity.User u = this.FBService.GetUserInfo();
Collection<Facebook.Entity.User> f = this.FBService.GetFriends();
Visual Basic
If (Not IsPostBack) Then
Dim u As Facebook.Entity.User = Me.FBService.GetUserInfo()
Dim f As Collection(Of Facebook.Entity.User) =
Me.FBService.GetFriends()
Optionally,ifyouprefertouseCookiesinsteadofSessionstopassFacebookSessioninformation
betweenpages,settheUseSessionpropertyoftheCanvasIFrameBasePagetofalse
Optionally,ifyouprefertonotautomaticallyredirectuserswhohavenotalreadyaddedyour
applicationtotheaddpage(ifyouprefertohaveaninformationpagewithalinktotheadd
functionality),settheAutoAddpropertyofCanvasIFrameBasePagetofalse
PublishWebsitetopubliclyavailablelocation
Accessapplicationusinghttp://apps.facebook.com/YOURCANVASPAGE
1.4 FBMLCanvasDevelopment
FBML(FacebookMarkupLanaguage)isasubsetofHTMLwithsomeFacebookspecificfeatures.The
secondtypeofFacebookCanvasapplicationthatissupportedistheFBMLcanvas.WithanFBML
canvas,thedeveloperisessentiallydevelopinganFBMLwebservicethattheFacebookservercan
invokeandtheservicewillemitFBMLthatcanberenderedasHTMLbythedisplayedpage.Thiscanvas
typeallowsforusingsomepowerfulfacebookspecificconstructsthathelptodevelopersprovidea
betterFacebookintegratedexperience.
HowtostartyourFBMLcanvasapplicationusingtheFacebookDeveloperToolkit.
Requestanewdeveloperapikeyfromhttp://www.facebook.com/developers/
Configurethefollowingfields.Thevaluesherearethevaluesusedbythesample,youcan
replacewithyourownvalues.
o CallbackURL:http://facebook.claritycon.com/FBML/
o CanvasPageURL:aspnetcanvasfbml
o UseIFRAME:false;UseFBML:true
o ApplicationType:Website
o Canyourapplicationbeaddedonfacebook:yes
o PostAddURL:http://apps.facebook.com/aspnetcanvasfbml(sameascanvaspage)
o DefaultProfileBox:Wide
o SideNavURL:http://apps.facebook.com/aspnetcanvasfbml(sameascanvaspage)
Createnewasp.netwebsiteinVisualStudio
AddreferencetoFacebook.dll
AddreferencetoFacebook.WebControls.dll
UpdateDefault.aspxtoremoveallofthedefaulthtmlinthepage,toensurenoFBMl
compatibilities.
Updatecodebehind(Default.aspx.cs)onDefault.aspxtosubclass
Facebook.WebControls.CanvasIFrameBasePage
Visual C#
using Facebook;
using Facebook.WebControls;
public partial class _Default : CanvasFBMLBasePage
{
Visual Basic
Imports Facebook
Imports Facebook.WebControls
Public Partial Class _Default
Inherits CanvasFBMLBasePage
AddcodetosetAPIkey,secret(Makesuretouseyourownapikeyandsecretacquiredduring
above)
Addcodetocallbase.Page_Loaded
Visual C#
private const string FACEBOOK_API_KEY = "YOURAPIKEYHERE";
private const string FACEBOOK_SECRET = "YOURSECRETHERE";
new protected void Page_Load(object sender, EventArgs e)
{
base.Api = FACEBOOK_API_KEY;
base.Secret = FACEBOOK_SECRET;
base.Page_Load(sender, e);
Visual Basic
Private Const FACEBOOK_API_KEY As String = "YOURAPIKEYHERE"
Private Const FACEBOOK_SECRET As String = "YOURSECRETHERE"
Shadows Protected Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs)
MyBase.Api = FACEBOOK_API_KEY
MyBase.Secret = FACEBOOK_SECRET
MyBase.Page_Load(sender, e)
AddcodetouseFacebookServicetoinvokeAPIcallsonbehalfoftheloggedinuser.
Visual C#
if (!IsPostBack)
{
// Use the FacebookService Component to populate Friends
Facebook.Entity.User u = this.FBService.GetUserInfo();
Collection<Facebook.Entity.User> f = this.FBService.GetFriends();
Visual Basic
If (Not IsPostBack) Then
Dim u As Facebook.Entity.User = Me.FBService.GetUserInfo()
Dim f As Collection(Of Facebook.Entity.User) =
Me.FBService.GetFriends()
Optionally,ifyouprefertonotautomaticallyredirectuserswhohavenotalreadyaddedyour
applicationtotheaddpage(ifyouprefertohaveaninformationpagewithalinktotheadd
functionality),settheAutoAddpropertyofCanvasIFrameBasePagetofalse
PublishWebsitetopubliclyavailablelocation
Accessapplicationusinghttp://apps.facebook.com/YOURCANVASPAGE
1.5 AJAXinIFrameCanvas
UsingtheASP.NETAJAXextensionswithinforIFrameCanvasapplicationisprettystraightforward.
However,oneimportantnote,AJAXfromanIFrameisnotsupportedinwithoutFramework3.5installed
ontheWebServer.ThisisabigobstacleforanyoneusingapublichostingserviceuntilFramework3.5
GoLivelicensingisavailable.ThefollowingwalkthroughassumesthatFramework3.5isinstalled.This
walkthroughdescribestheweb.configupdatesrequiredtoenabletheasp.netajaxextensionsonyour
existingasp.netwebsite.AndIsimplepageillustratingtheusage.
1. InstallASP.NETAjaxExtensionsfromhttp://ajax.asp.net/
2. Install.NETFramework3.5from
http://www.microsoft.com/downloads/details.aspx?FamilyId=E3715E6FE123428B8A0F
028AFB9E0322&displaylang=en
3. Openyourweb.config,inthesystem.websectionaddthefollowingline:
<pages>
<controls>
<add tagPrefix="asp" namespace="System.Web.UI"
assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</controls>
</pages>
Thiswillsaveyouhavingtohavethefollowingdirectiveatthetopofeachpage:
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI" TagPrefix="asp" %>
4. VerifythatSystem.WebsectionhasthefollowinghttpHandlersandhttpModulesconfigured,if
not,addthemissingsettings:
<httpHandlers>
<remove verb="*" path="*.asmx"/>
<add verb="*" path="*.asmx" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add verb="*" path="*_AppService.axd" validate="false"
type="System.Web.Script.Services.ScriptHandlerFactory,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
<add verb="GET,HEAD" path="ScriptResource.axd"
type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions,
Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
validate="false"/>
</httpHandlers>
<httpModules>
<add name="ScriptModule" type="System.Web.Handlers.ScriptModule,
System.Web.Extensions, Version=1.0.61025.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
5. Addanew.aspxfile(inourexample,AJAXSample.aspx
6. AddaScriptManagertothe.aspxpage
<asp:ScriptManager ID="ScriptManager1" runat="server" />
7. AddanUpdatePanelwithContentTemplate
<asp:UpdatePanel ID="upPanel" runat="server">
<ContentTemplate>
<asp:Label id="lblUpdate" runat="server" Text="Before click" />
<asp:Button ID="btnAjax" runat="server" Text="Fire Ajax"
OnClick="btnAjax_Click" />
</ContentTemplate>
</asp:UpdatePanel>
8. Thatisit,nowcontrolswithinyourUpdatePanelwillbeupdatedandfireeventswithoutposting
backthemainBrowserthread.
9. Inourexample,wecatchthebuttonpressandupdatethelabelandbuttonincodebehind.The
pageisupdatedwithoutpostingback.
Visual C#
protected void btnAjax_Click(object sender, EventArgs e)
{
lblUpdate.Text = "After click";
btnAjax.Text = "Fired Ajax";
btnAjax.Enabled = false;
}
Visual Basic
Protected Sub btnAjax_Click(ByVal sender As Object, ByVal e As
EventArgs)
lblUpdate.Text = "After click"
btnAjax.Text = "Fired Ajax"
btnAjax.Enabled = False
End Sub
1.6 SilverlightinIFrameCanvas
UsingSilverlightinaCanvaspageistricky.YoucannotdirectlyreferencetheFacebook.dllfroma
Silverlightcontrol.ThefollowingisalistofissuespreventingdirectusingoftheFacebookServicefrom
Silverlight.
1. SomenamespacesusedintheFacebook.dll(wrappertotheAPI)arenotsupportedinSilverlight
namespace.Mostnotably:System.XML,System.Web.
2. Silverlight1.1Alphadoesnotsupportcrossdomainposts.
3. ItwillbetoughtomanagethefacebookloginprocessfromtheSilverlightcontrol,sincewecan
notshowthefacebookhostedloginpage.
Withtheselimitations,theonlytechniqueavailabletouseSilverlightistodo2things.Firsthavethe
ASPXpagethathoststheSilverlightcontenthandletheauthenticationandpasstheFacebookSession
informationtotheSilverlightcontrol,andthenhavetheSilverlightcontroluseaproxywebserviceto
accesstheFacebookService.Hereisastepbystepexampleofasimpleexamplethatretrievesanarray
ofFacebookfriendsfromSilverlight:
Addanewwebservice(SilverlightService.asmx)totheCanvaswebsiteproject.Thiswebservice
isaproxyusedbythesilverlightapplicationtocallFacebook
Updatethewebsiteprojectweb.configtosupportthewebservice.
AddaScriptServiceattributetoSilverlightServicetoenableittosupportJSONcalls
AddWebMethodGetFriendswrappingtheFacebookService.GetFriends(),thismethodneedsto
takethe4parametersthatcompriseafacebooksession,sothatcallscanmaintaincontext.
Visual C#
[WebService(Namespace = "http://facebook.claritycon.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class SilverlightService : System.Web.Services.WebService
{
Facebook.Components.FacebookService _fbService = new
Facebook.Components.FacebookService();
[WebMethod]
public UserJSON[] GetFriends(string api, string secret, string session,
string userid)
{
Visual Basic
<WebService(Namespace := "http://facebook.claritycon.com/"),
WebServiceBinding(ConformsTo := WsiProfiles.BasicProfile1_1),
System.Web.Script.Services.ScriptService> _
Public Class SilverlightService
Inherits System.Web.Services.WebService
Private _fbService As Facebook.Components.FacebookService =
New Facebook.Components.FacebookService()
<WebMethod> _
Public Function GetFriends(ByVal api As String, ByVal secret As String,
ByVal session As String, ByVal userid As String) As UserJSON()
CreatedastrippeddownversionoftheFacebook.Entity.UserclassthatisserializiablebyJSON.
JSONcan'tserializeenumsorsubclasses.So,forthisIjuststrippedthemout.Thisiscalled
UserJSONandiscurrentlyjustamemberofmyASPNETPlatformSampleswebsite.
IntheGetFriendsWebMethod,convertedCollectionofUsersreturnedfromFacebookcallto
ArrayofJSONcompatibleusers.
Visual C#
public UserJSON[] GetFriends(string api, string secret, string session,
string userid)
{
_fbService.ApplicationKey = api;
_fbService.Secret = secret;
_fbService.SessionKey = session;
_fbService.UserId = userid;
Collection<Facebook.Entity.User> friends = _fbService.GetFriends();
UserJSON[] x = UserJSON.ConvertFacebookUserArray(friends);
Visual Basic
Public Function GetFriends(ByVal api As String, ByVal secret As String,
ByVal session As String, ByVal userid As String) As UserJSON()
_fbService.ApplicationKey = api
_fbService.Secret = secret
_fbService.SessionKey = session
_fbService.UserId = userid
Dim friends As Collection(Of Facebook.Entity.User) =
_fbService.GetFriends()
Dim x As UserJSON() = UserJSON.ConvertFacebookUserArray(friends)
Return x
CreateanewCanvaspage(IFrame\Silverlight.aspx),alongsidetomyotherIFramecanvaspages
Addaplaceholdersinthe.aspxfortheSilverlightcontroland4hiddenfieldstostorethe
facebookcontext.
Visual C#
<head>
<title>Silverlight Project Test Page </title>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript" src="CreateSilverlight.js"></script>
</head>
<body>
<form id="Form1" runat="server">
<asp:HiddenField ID="hidAPI" runat="server" />
<asp:HiddenField ID="hidSecret" runat="server" />
<asp:HiddenField ID="hidSession" runat="server" />
<asp:HiddenField ID="hidUser" runat="server" />
<div id="SilverlightControlHost" >
<script type="text/javascript">
createSilverlight();
</script>
</div>
</form>
Visual Basic
<head>
<title>Silverlight Project Test Page </title>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript" src="CreateSilverlight.js"></script>
</head>
<body>
<form id="Form1" runat="server">
<asp:HiddenField ID="hidAPI" runat="server" />
<asp:HiddenField ID="hidSecret" runat="server" />
<asp:HiddenField ID="hidSession" runat="server" />
<asp:HiddenField ID="hidUser" runat="server" />
<div id="SilverlightControlHost" >
<script type="text/javascript">
createSilverlight();
</script>
</div>
</form>
Addcodeincodebehindtopopulatehiddenfields(sotheycanbeaccessedbysilverlight
control).
Visual C#
public partial class Silverlight : CanvasIFrameBasePage
{
private const string FACEBOOK_API_KEY =
"c559128010f3edee33796fd4205361c2";
private const string FACEBOOK_SECRET =
"85887d1c9a8334e5059742468a5400ee";
new protected void Page_Load(object sender, EventArgs e)
{
base.Api = FACEBOOK_API_KEY;
base.Secret = FACEBOOK_SECRET;
base.Page_Load(sender, e);
hidAPI.Value = this.FBService.ApplicationKey;
hidSecret.Value = this.FBService.Secret;
hidSession.Value = this.FBService.SessionKey;
hidUser.Value = this.FBService.UserId;
Visual Basic
Partial Public Class Silverlight
Inherits CanvasIFrameBasePage
Private Const FACEBOOK_API_KEY As String =
"c559128010f3edee33796fd4205361c2"
Private Const FACEBOOK_SECRET As String =
"85887d1c9a8334e5059742468a5400ee"
Protected Shadows Sub Page_Load(ByVal sender As Object, ByVal e As
EventArgs)
MyBase.Api = FACEBOOK_API_KEY
MyBase.Secret = FACEBOOK_SECRET
MyBase.Page_Load(sender, e)
hidAPI.Value = Me.FBService.ApplicationKey
hidSecret.Value = Me.FBService.Secret
hidSession.Value = Me.FBService.SessionKey
hidUser.Value = Me.FBService.UserId
CreateanewsilverlightprojectusingOrcas
AddawebreferencetotheaboveASMXfile(onyourpublicdomain)
Addcodeinpage_loadedeventhandlerofxamlcodebehindtocalltheGetFriendsmethodon
theWebServicetoretrieveanarrayoffriends.
Writetexttoatextblockwiththecountthatwasfound.
AddaSilverlightReferenceintothewebsiteproject.Thisessentiallycopiesthe.xamlfrom
theSilverproject,andthecompiled.xaml.csintoaClientBinfolderofthewebsiteprojectso
theycanbeaccessedfromwithinthewebsite.
Youcanseeitinaction,bygoingtomyIFramecanvassample.Afterlogginginandaddingthe
application,youshouldhaveaSilverlightdemolinkwhichwillshowtheSilverlightpage.
ThecodefromthiswalkthroughisintheASPNETPlatformSampleswebprojectand
SilverlightWebServiceClient
2 Prerequisites
First,youdownloadoneoftheVisualStudioExpressproducts.Todevelopadesktopapplication,you
canuseVisualC#2005ExpressEdition(orlater)orVisualBasic2005ExpressEdition(orlater).Ifyou
wanttobuildawebapplication,youcanuseVisualWebDeveloper2005ExpressEdition(orlater).
Next,inordertousetheFacebookAPI,youmustfirstregisterforadeveloperaccountwithFacebookat
http://developers.Facebook.com/account.php.Youwillneedtospecifywhetheryourapplicationisa
WebsiteoraDesktopapplication.Afterregisteringforyourdeveloperaccount,youwillreceiveandAPI
keyandsecret.ThesearecriticalforusingtheFacebookAPIandyoushouldkeepthisreadilyavailable
3 Introduction
Thisdocumentoutlinesthecomponentsandcontrolsthatareavailablefortohelpsimplifydevelopment
againsttheFacebookAPI.ThemaincomponentistheFacebookServicecomponent.The
FacebookServicewrapstheFacebookAPIandprovidesaneasytouseinterfaceforcallingthedifferent
methodscurrentlyavailableinthe1.0versionoftheFacebookAPI.Inaddition,someWindowsandweb
controlswereinstalledwhichwillprovideaquickwaytostartleveragingtheFacebookdatainyour
application.Wevealsoprovidedyouwithsomecoolfunsamples.Thesecanbefoundin<INSERT
DIRECTORYHERE>.Additionally,weveprovideallthesourcecodefortheAPI,components,controls
andsamplesforyoutoexplore.
4 Overview
AllofthesectionsbelowassumethatthedeveloperhassignedupforaFacebookdeveloperaccount
andreceivedanAPIkeyandsecretfromFacebook.
4.1 FacebookAPIOverview
TheFacebookAPIisaRESTinterfaceallowingapplicationstopostaspecificHTTPaddressand
receivestructuredXMLrepresentingtherequestedFacebookdata.The1.0versionoftheAPI
containsprimarilyGetoperations,anddoesnotprovidepersonalorcontactinformationfor
Facebookusers.TheonlySettypeoperationsthatareavailableareCreateAlbum,UploadPhoto
andAddTag.
Formoreinformationontheavailablefunctions,seetheAPIdocumentationat
http://developers.Facebook.com/documentation.php?v=1.0
4.2 UsingtheFacebookServicetoAccesstheAPI
TheFacebook.dllthatwasinstalledat%ProgramFiles%\Coding4Fun\Facebook\Binariescontains
theFacebookServicecomponent.Thiscomponentcontainsallthemethodsthatwraptheavailable
APIcalls.Tousethiscomponent,eachapplicationmustprogrammaticallysettheirapplicationkey
andsecret.ForspecificsoninteractingwiththeFacebookServiceseetheDesktopandWeb
Developmentbelow.ThemethodswithintheFacebookServicereturnstronglytypeddataobjects
representingthedata.Theseobjectsareintendedtosimplifythedeveloperexperienceusingthe
API.
4.2.1
InfiniteSessions
TheFacebookAPIsupportsInfiniteSessions.Whatthismeansisthatusersofcustomdeveloped
Facebookdesktopapplicationshavetheabilitytosavetheircredentialsandnotberequiredto
logintotheapplicationonsubsequentuses.Inorderforanapplicationtotakeadvantageof
infinitesessions,theapplicationshouldcheckSessionExpirespropertyoftheFacebookService
afteraSessionisinitiated.Ifthispropertyisfalse,theapplicationcanstoretheuserId,Secretand
SessionKeythatareassociatedwiththeuserandsetthemontheFacebookServicewheneverthis
userreturns.
4.3 FacebookDesktopDevelopment
TostartutilizingtheFacebookAPI,youwillneedtoaddtheFacebookServicecomponenttoyour
project.TodothisjustdraganinstanceofFacebookServicefromthetoolboxontothecomponent
trayandenteryourAPIKeyandSecret.
TheFacebookServicecomponentcontainsmethodsthatwrapallofthemethodsoftheFacebook
API.Thefollowingprovidesanexampleforgettingallthefriendsoftheloggedinuser.This
methodreturnsagenericcollectionofUserobjects.TheUserobjectisastronglytyped
representationofaFacebookUserprofile.
Visual C#
using System.Collections.Generic;
using System.Collections.ObjectModel;
4.4 FacebookWebDevelopment
TheauthenticationprocessforaWebApplicationismoreinvolvedthanforaWindowsapplication.
Whenthedeveloperaccountissetup,thedevelopermustchoosewhethertheirapplicationisaWeb
applicationorDesktopapplication.Inthecaseofawebapplication,thedevelopermustspecifyareturn
url.Thisistheurlthatusersofthewebapplicationwillberedirectedtoafterlogginginonthe
Facebookhostedloginpage.Forthesamplewebsite,itissetuptoreturnto
http://localhost/FacebookWebSample/default.aspx.TorunanddebugtheFacebookWebSample
project,youmustconfigureyourVisualStudioWebProjecttostartyourwebapplicationusingthis
address.Becauseofthisrequirement,thesimplestwaytoconfiguretoruntheWebSampleisusingIIS.
(Sinceitrunsonport80andhandlesaddressesliketheabove)
1. CreateanIISVirtualDirectorycalledFacebookWebSamplepointedatthelocationofyour
FacebookWebSample.
2. SettheWebProjecttostartusingthiswebsite.
a. RightClickFacebookWebSampleinVisualStudioSelectPropertyPages
b. SelectStartOptions
c. ClickStartURLradiobuttonEnterhttp://localhost/FacebookWebSample/default.aspx
3. Writecodetohandle3states.
a. Ifwedonthaveanauth_token,redirecttotheFacebookhostedloginpage.
b. Ifwehaveanauth_token,startasessiononbehalfoftheuser.
c. StoretheuserssessioninformationformakingcallstotheFacebookservice.
SeetheCodeSnippetssectionformoredetails.
4.5 FacebookCanvasDevelopment
Inadditiontostandalonewebanddesktopapplications,FacebookalsosupportsCanvasapplications.
Canvasapplicationsareintegrateddirectlyintothewebsiteuserexperienceonthefacebook.com
website.Canvasapplicationhavetheabilitytodisplayinformationonausersprofile,publishtousers
minifeedsandspreadthemselvesorganicallythroughFacebookssocialnetwork.Formoreinformation
aboutbuildingaFacebookCanvasapplicationreadAnatomyofaFacebookApplicationhere,
http://developers.facebook.com/anatomy.php.
Canvasapplicationcanbeoneoftwotypes.FBMLCanvasapplicationsleverageFacebookMarkup
languagetoprovideaconsistentintegrateduserexperienceforFacebookusers.FBMLcanvas
applicationsessentiallyareconstructedbythedeveloperbuildingaFBMLWebServicethatcanbe
calledbytheFacebookServerandreturnsomeFBML.TheFacebookServerwillthentranslatethat
FBMLintoHTMLtodisplayonFacebookhostedpage.ThesecondtypeofCanvasapplicationisthe
IFrameCanvasapplication.Inthistypeofcanvas,theFacebookwebpagewillsimplyshowanIFrameto
contenthostedbythedevelopersapplication.ThistypeofcanvascannotleverageFBMLfunctionality,
butdoeshavetheadvantageofamuchmoretypicallywebdevelopmentexperience.
TheFacebookDeveloperToolkitprovidesinfrastructureforbuildingbothtypesofcanvasapplications.
First,thereisaCanvasFBMLBasePageandCanvasIFrameBasePageintheFacebook.WebControls
assemblies.Thesebasepagestakecareofalloftheplumbingneededtosuccessfullyhostacanvas
applicationonthefacebooksite.Inaddition,theASPNETPlatformSampleswebsiteshowssamplesof
bothtypesofCanvaspagesandhowtolinktoothercanvaspageswithonecanvasapplication.See
Sections1.3and1.4aboveforadetailedwalkthrough
4.6 UsingLINQ
Thetoolkitcontainssomesamplecodeshowing(bothawebapplicationandWindowsapplication
version)howLINQandOrcascanbeusedtoprovidearichersetofdevelopmentfeaturesagainstthe
FacebookAPIdata.ThesamplesincludedwillonlyworkinOrcas(thecodenameforthenextversion
ofVisualStudio)andshowhowwecanrightcodeusingasyntaxsimilartoSQLtofilterandsearch
throughthefriendsthatarereturnedfromFacebook.ThesamplesleverageLINQoverXMLandrunthe
filteringdirectlyagainstthereturnedXML.Alternatively,theLINQcodecouldjustaseasilyhavebeen
writtenagainsttheGenericCollectionsreturnedbytheourtoolkit.FormoreinformationonLINQ,
checkouthttp://msdn2.microsoft.com/enus/netframework/aa904594.aspx.Ifyouwanttodownload
OrcasandtryoutLINQandtheenclosedsamples,youcandosohere,
http://msdn.microsoft.com/vstudio/express/future.
ThesourceforthesesamplesisinstalledtoC:\ProgramFiles\Coding4Fun\Facebook\LINQSamples
5 DetailedClassDesign
5.1 Facebook.Components
5.1.1
FacebookServiceClass
This class contains methodsthat wrap the Facebook API and return strongly typedobjects
representing Facebook data. Additionally, this class has functionality to encapsulate the
Facebooklogin processfor bothMicrosoftWindowsbasedclientsandASP.NETweb based
clients.
Figure1:FacebookServiceClass
5.1.1.1 Property:ApplicationKey
Thispropertyisrequiredtobesetbyallconsumingapplications.Thispropertyshouldbe
settotheAPIkeyacquiredfromFacebookwhendevelopersignedupforaFacebook
developeraccount.
Definition:public string ApplicationKey
5.1.1.2 Property:IsDesktopApplication
Thispropertyisanindicatorusedtodetermineiftheconsumingapplicationisadesktop
(Windows)orwebbasedapplication.Thisisneededbecausetheapplicationsecretis
handleddifferentlyforWindowsandwebapplications.
Definition:public bool IsDesktopApplication
5.1.1.3 Property:Secret
Thispropertyisrequiredtobesetbyallconsumingapplications.Thisisthesecretusedto
encryptparameterspassedtotheFacebookAPI.Forwebapplications,thesecretis
constantandsetatthebeginningofinteractionwiththeservice.ForWindows
applications,aninitialsecretisrequiredtoestablishasession,butanewsecretis
acquiredthatcoincideswitheachsession.
Definition:public string Secret
5.1.1.4 Property:SessionExpires
Thispropertyisanindicatorofwhetherthecurrentsessionisaninfinitesessionornot.
ThevalueisdeterminedafterauseroftheconsumingapplicationlogsinontheFacebook
hostedwebpage.Consumingapplicationscanleverageaninfinitesessionbystoringthe
sessioninformationlocallyandbypassingthelogonprocessinsubsequentinteractions
withtheuser.
Definition:public bool SessionExpires
5.1.1.5 Property:SessionKey
Thispropertystoresthesessionkeyforthecurrentusersession.Thiscaneitherbesetby
theconsumingapplication(whichwouldtypicallybedonewhentheconsuming
applicationrecognizesauserthathasaninfinitesessionestablished)orwillbesetbythe
FacebookServiceafterthelogonprocessiscomplete
Definition:public string SessionKey
5.1.1.6 Property:UserId
ThispropertyisstoredtheFacebookuserid.SimilartotheSessionKey,inthecaseof
infinitesessionsthecomsumingapplicationwillsetthispropertywiththeknownUserId,
otherwisethispropertywillbesetbythelogonprocess.
5.1.1.7 Method:AddTag
ThismethodwrapstheFacebookAPImethodphotos.addTag.Thismethodisusedtoadd
tagstoanypendingphotos.Apendingphotoisaphotothathasbeenuploadedbutnot
yetconfirmed.
Definition:public void AddTag(string photoId, string tagText, string
tagUserId, int xCoord, int yCoord)
Parameters:
Parameter
Description
photoId
TheFacebook identifierofthependingphototobetagged
tagText
Themessagethatshouldbeassociatedwiththetag.UsethisORtag
UserId.Notboth.
tagUserId
TheFacebook useridofthepersonthetagpointsto
xCoord
TheXcoord(inpixels)wherethetagshouldbegininthespecified
picture
yCoord
TheYcoord(inpixels)wherethetagshouldbegininthespecified
picture
ReturnType:N/A
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshhold
5.1.1.8 Method:AreFriends
ThismethodwrapstheFacebookAPImethodfriends.areFriends.Thismethodisusedto
determineiftwoFacebookusersarefriendsornot.
Parameters(1):
Parameter
Description
userId1
TheFacebook identifierofthefirstuser
userId2
TheFacebook identifieroftheseconduser
Parameters(2):
Parameter
Description
user1
TheastronglytypedinstanceofaUserrepresentingthefirstFacebook
user
user2
TheastronglytypedinstanceofaUserrepresentingthesecond
Facebookuser
ReturnType:bool:trueif2usersarecurrentlyFacebookfriends,otherwisefalse.
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.9 Method:ConnectToFacebook
Thismethodisnottypicallyusedbytheconsumingapplication.TheFacebookServicewill
checkifthereisavalidsessionthatitcanusetomakeAPIcalls,ifnotitwillinvokethe
ConnectToFacebookmethod.Thismethodisonlyneededbydesktopapplicationsand
usesahostedwebbrowsertoallowtheusertologintotheFacebookhostedloginpage.
Description
None
ReturnType:N/A
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.10 Method:CreateSession
Thismethodhasapublicversionandaprivateversion.Theprivateversionisusedfor
WindowsapplicationsandiscalledfromConnectToFacebook.Thepublicversiontakesin
anauthtokenandisusedbywebbasedapplications.Webbasedapplicationsgetthe
authtokenasaurlparameteraftertheuserloginsontheFacebookhostedwebpage.The
webapplicationthenneedstostartthesessionusingthismethodandpassingintheauth
token.
Definition(1):private void CreateSession()
Definition(2):public void CreateSession(string authToken)
Parameters(1):
Parameter
none
Parameters(2):
Description
None
Parameter
authToken
Description
Theauthenticationtoken returnedtothewebapplicationfromthe
Facebookloginpage.
ReturnType:N/A
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.11 Method:GetEventMembers
ThismethodwrapstheFacebookAPImethodevents.getMembers.Thismethodisusedto
returnalltheusersthathavebeeninvitedtoaneventandtheircurrentrsvpstatus.
Definition:public Collection<EventUser> GetEventMembers(string
eventId)
Parameters:
Parameter
eventId
Description
TheFacebook identifieroftheevent
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.12 Method:GetEvents
ThismethodwrapstheFacebookAPImethodevents.get.Thismethodisusedtoretrieve
eventinformation.Thereareoverridessupportinggetbyeventid,useridanddate.
Definition(1):public Collection<FacebookEvent> GetEvents()
Definition(2):public Collection<FacebookEvent> GetEvents(string
userId)
Definition(3):public Collection<FacebookEvent>
GetEvents(Collection<string> eventList)
Definition(4):public Collection<FacebookEvent>
GetEvents(Collection<string> eventList, string userId)
Definition(5):public Collection<FacebookEvent>
GetEvents(Collection<string> eventList, string userId, DateTime?
startDate, DateTime? endDate)
Parameters(1):
Parameter
None
Description
GetEventsthattheloggedinuserisinvitedto
Parameters(2):
Parameter
userId
Description
TheFacebook userIdthateventsareretrievedfor.Willreturnall
eventsthispersonisinvitedto.
Parameters(3):
Parameter
eventList
Description
AcollectionofeventIds.Willreturntheeventinformationforeach
eventmatchinganeventidpassedin.
Parameters(4):
Parameter
userId
Description
TheFacebook userIdthateventsareretrievedfor.Willreturnevents
thispersonisinvitedtothatarealsospecifiedintheeventList.
AcollectionofeventIds.Willreturntheeventinformationforeach
eventmatchinganeventidpassedinthathasthespecifiedUserId
invited.
eventList
Parameters(5):
Parameter
Description
userId
TheFacebook userIdthateventsareretrievedfor.Willreturnevents
thispersonisinvitedtothatarealsospecifiedintheeventList.
eventList
AcollectionofeventIds.Willreturntheeventinformationforeach
eventmatchinganeventidpassedinthathasthespecifiedUserId
invited.
startDate
Onlyretrieveeventsmatchingtheabovecriteriaandstartingafterthis
date.
endDate
Onlyretrieveeventsmatchingtheabovecriteriaandendingbeforethis
date.
ReturnType:Collection<FacebookEvent>
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.13 Method:GetFriends
ThismethodwrapstheFacebookAPImethodfriends.get.Thismethodisusedtogetall
thefriendsoftheloggedinuser.
Definition:public Collection<User> GetFriends()
Parameters:
Parameter
none
Description
Getfriendsoftheloggedinuser
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.14 Method:GetFriendsAppUsers
ThismethodwrapstheFacebookAPImethodfriends.getAppUsers.Thismethodisused
togetallthefriendsoftheloggedinuserthatarealsousersofthisconsuming
application.
Definition:public Collection<User> GetFriendsAppUsers()
Parameters:
Parameter
none
Description
Getfriendsoftheloggedinuserthatareusersofthisapplication
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.15 Method:GetFriendsNonAppUsers
ThismethodisnotsupportedbytheFacebookAPI.Thismethodisusedtogetallthe
friendsoftheloggedinuserthatarenotusersofthisconsumingapplication.
Definition:public Collection<User> GetFriendsNonAppUsers()
Parameters:
Parameter
None
Description
Getfriendsoftheloggedinuserthatareusersofthisapplication
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.16 Method:GetGroupMembers
ThismethodwrapstheFacebookAPImethodgroups.getMembers.Thismethodisto
retrieveprofileinformationaboutallFacebookusersthataremembersofaparticular
group.
Definition:public Collection<GroupUser> GetGroupMembers(string
groupId)
Parameters:
Parameter
groupId
Description
TheFacebook identifierofthegroup
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.17 Method:GetGroups
ThismethodwrapstheFacebookAPImethodgroups.get.Thismethodisusedtoretrieve
thegroupsmatchingaspecificcriteria.
Definition(1): public Collection<Group> GetGroups()
Definition(2): public Collection<Group> GetGroups(string userId)
Definition(3): public Collection<Group> GetGroups(Collection<string>
groupsList)
Parameters(1):
Parameter
None
Description
Getallgroupsfortheloggedinuser
Parameters(2):
Parameter
userId
Description
TheFacebook userIdtoreturngroupsfor
Parameters(3):
Parameter
groupList
Description
Acollectionofgroupids.Returnallgroupsmatchingagroupidinthe
list.
Parameters(4):
Parameter
Description
userId
TheFacebook userIdtoreturngroupsfor
groupList
Acollectionofgroupids.Returnallgroupsmatchingagroupidinthe
list.
ReturnType:Collection<Group>
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.18 Method:GetGroups
ThismethodwrapstheFacebookAPImethodnotifications.get.Thismethodisusedto
retrievethenotificationsforthecurrentuser.
Definition: public Notifications GetNotifications()
Parameters:
Parameter
None
Description
Getallnotificationsfortheloggedinuser
ReturnType:Notifications
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.19 Method:GetPhotoAlbums
ThismethodwrapstheFacebookAPImethodphotos.getAlbums.Thismethodisusedto
getphotoalbumdetailsbasedonsearchcriteria
Definition(1):public Collection<Album> GetPhotoAlbums()
Definition(2):public Collection<Album> GetPhotoAlbums(string userId)
Definition(3):public Collection<Album>
GetPhotoAlbums(Collection<string> albumList)
Parameters(1):
Parameter
None
Description
Getallalbumsfortheloggedinuser
Parameters(2):
Parameter
userId
Description
Facebookuseridtoretrieveallalbumsfor
Parameters(3):
Parameter
albumList
Description
CollectionofFacebook albumidstoretrieve
Parameters(4):
Parameter
Description
userId
Facebookuseridtoretrievealbumsfor
albumList
CollectionofFacebook albumidstoretrieve
ReturnType:Collection<Album>
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.20 Method:GetPhotos
ThismethodwrapstheFacebookAPImethodphotos.get.Thismethodisusedtoget
photosbasedonsearchcriteria.
Definition(1):public Collection<Photo> GetPhotos(string albumId)
Definition(2):public Collection<Photo> GetPhotos(Collection<string>
photoList)
Definition(3): public Collection<Photo> GetPhotos(User user)
Definition(4):public Collection<Photo> GetPhotos(string albumId,
Collection<string> photoList)
Parameters(1):
Parameter
albumId
Description
TheFacebook identifierofthealbumtoretrievephotosfor
Parameters(2):
Parameter
photoList
Description
CollectionofFacebook photoidentifiertoreturninformationabout
Parameters(3):
Parameter
User
Description
Theuserofthealbumtoretrievephotosfor
Parameters(4):
Parameter
Description
albumId
TheFacebookidentifierofthealbumtoretrievephotosfor
photoList
CollectionofFacebookphotoidentifiertoreturninformationabout
Parameters(5):
Parameter
Description
albumId
TheFacebook identifierofthealbumtoretrievephotosfor
photoList
CollectionofFacebook photoidentifiertoreturninformationabout
User
Theuserofthealbumtoretrievephotosfor
ReturnType:Collection<Photo>
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.21 Method:GetTags
ThismethodwrapstheFacebookAPImethodphotos.getTags.Thismethodisusedto
retrievealltagsforaparticularphoto.
Definition:public Collection<PhotoTag> GetTags(Collection<string>
photoList)
Parameters:
Parameter
photoList
Description
CollectionofFacebook photoidentifierstoreturntagsfor
ReturnType:Collection<PhotoTag>
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.22 Method:GetUserInfo
ThismethodwrapstheFacebookAPImethodusers.getInfo.Thismethodisusedto
retrieveprofileinformationforasetofusers.
Definition(1):public User GetUserInfo()
Definition(2):public Collection<User> GetUserInfo(string userIds)
Definition(3):public Collection<User> GetUserInfo(Collection<string>
userIds)
Parameters(1):
Parameter
None
Description
Gettheuserprofilefortheloggedinuser
Parameters(2):
Parameter
userIds
Description
CommaseparatedlistofFacebook useridentifiers
Parameters(3):
Parameter
userIds
Description
CollectionofFacebookuseridentifiers
ReturnType:User
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.23 Method:UploadPhoto
ThismethodwrapstheFacebookAPImethodphotos.upload.Thismethodisusedto
uploadanewphoto.Theuploadedphotowillbeconsideredpendinguntiltheuser
utilizesthewebsitetoconfirmthephoto.
Definition:public void UploadPhoto(string albumId, FileInfo
uploadFile)
Parameters:
Parameter
Description
albumId
Thealbumidentifiertouploadthephototo.Ifnull,thenwilluploadto
defaultalbum
uploadFile
Filecontainingthephototoupload.
ReturnType:N/A
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.24 Method:SetFBML
ThismethodwrapstheFacebookAPImethodprofile.setFBML.Thismethodisusedtoadd
profilefunctionalityusingFBML.
Description
FBML
Parameters(2):
Parameter
Description
markup
FBML
userId
Thefacebookidentifieroftheusers profiletowriteto
ReturnType:stringstatus
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.25 Method:DirectFQLQuery
ThismethodwrapstheFacebookAPImethodfql.query.Thismethodisusedtoexecute
anyarbitraryFQLandreturntheXMLresult.
Definition:public string DirectFQLQuery(string query)
Parameters:
Parameter
query
Description
AnyFQLquery
ReturnType:xmlstring
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.26 Method:SendNotification
ThismethodwrapstheFacebookAPImethodnotification.send.Thismethodisusedto
postamessagetoausersminifeed.
Definition(1):public string SendNotification(string markup, string
toList)
Parameters(1):
Parameter
Description
markup
FBMLforthenotification
toList
Commaseparatedlistofrecipientuserids
Parameters(2):
Parameter
Description
markup
FBMLforthenotification
toList
Commaseparatedlistofrecipientuserids
FBMLforemailbody
ReturnType:stringstatus
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.27 Method:SendRequest
ThismethodwrapstheFacebookAPImethodnotifications.sendRequest.Thismethodis
usedtosendaninvitetoaneventorgroup
Definition:public string SendRequest(string markup, string toList,
string requestType, Uri imageUrl, bool isInvite)
Parameters:
Parameter
Description
markup
FBMLforthenotification
toList
Commaseparatedlistofrecipientuserids
requestType
GrouporEvent
imageUrl
Urlofimagetodisplayintherequest
isInvite
Whethertherequestisaninvitationornot
ReturnType:stringstatus
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.28 Method:PublishAction
ThismethodwrapstheFacebookAPImethodfeed.publishActionOfUser.Thismethodis
publishtheactionofauser
Definition:public string PublishAction(string title, string body,
Collection<PublishImage> images)
Parameters:
Parameter
Description
title
Thealbumidentifiertouploadthephototo.Ifnull,thenwilluploadto
defaultalbum
body
Filecontainingthephototoupload.
images
Theurlandlinkofupto4images
Parameters(2):
Parameter
Description
title
Thealbumidentifiertouploadthephototo.Ifnull,thenwilluploadto
defaultalbum
body
Filecontainingthephototoupload.
images
Theurlandlinkofupto4images
priority
1100
ReturnType:stringstatus
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.29 Method:PublishStory
ThismethodwrapstheFacebookAPImethodfeed.publishStoryToUser.Thismethodis
publishastorytoaspecificuser
Definition(1):public string PublishStory(string title, string body,
Collection<PublishImage> images)
Definition(2):public string PublishStory(string title, string body,
Collection<PublishImage> images, int priority)
Parameters(1):
Parameter
Description
title
Thealbumidentifiertouploadthephototo.Ifnull,thenwilluploadto
defaultalbum
body
Filecontainingthephototoupload.
images
Theurlandlinkofupto4images
Parameters(2):
Parameter
Description
title
Thealbumidentifiertouploadthephototo.Ifnull,thenwilluploadto
defaultalbum
body
Filecontainingthephototoupload.
images
Theurlandlinkofupto4images
priority
1100
ReturnType:stringstatus
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.1.1.30 Method:GetLoggedInUser
ThismethodwrapstheFacebookAPImethodusers.GetLoggedInUSer.Thismethodis
usedtogetthefacebookuseridofthecurrentlyloggedinuser.
Definition:public string GetLoggedInUser()
Parameters:
Parameter
N/A
Description
ReturnType:N/A
Exceptions:
FacebookException:Thisbaseclassofallexceptions.Ifexceptioncouldnotbe
classified,FacebookExceptionwillbeused.
FacebookInvalidUserException:Theuserthatthecallwasmadeonbehalfofis
notvalid.
FacebookRequestLimitException:Indicatesthattheconsumingapplicationhas
madetoomanyFacebookAPIcallsinshortperiodoftime.
FacebookServiceUnavailableException:Indicatesthatthewebsiteusedtohost
theFacebookRESTclientwasnotavailable.
FacebookSigningException:IndicatesthatthesecretorAPIkeywerenot
specifiedorwereinvalid.
FacebookTimeoutException:IndicatesthattheFacebookAPIdidnotrespondin
awithinthetimeoutthreshold
5.2 FacebookDataObjects
5.2.1
AlbumClass
ThisclassrepresentsaFacebookphotoalbum.
5.2.1.1 Property:AlbumId
TheFacebookidentifierofthealbum
Definition:public string AlbumId
5.2.1.2 Property:CoverPhotoId
TheFacebookidentifierofphotothatisusedasthecoverphotoforthealbum
Definition:public string CoverPhotoId
5.2.1.3 Property:CreateDate
Thedatethatthealbumwascreated
Definition:public DateTime CreateDate
5.2.1.4 Property:Description
Theuserentereddescriptionofthealbum
Definition:public string Description
5.2.1.5 Property:Location
Thelocationthatthealbumpertainsto
Definition:public string Location
5.2.1.6 Property:ModifiedDate
Thedatethatthisalbumwaslastupdated
Definition:public DateTime ModifiedDate
5.2.1.7 Property:Name
Thenameofthealbum
Definition:public string Name
5.2.1.8 Property:OwnerUserId
TheFacebookuseridofthepersonwhocreatedthealbum
Definition:public string OwnerUserId
5.2.2
PhotoClass
ThisclasscontainstheinformationaboutaFacebookPhoto.
5.2.2.1 Property:AlbumId
AFacebookuniqueidentifierofthealbumthatthephotoispartof.
5.2.2.2 Property:Caption
Thecaptionofthephoto.
Definition:public string Caption
5.2.2.3 Property:CreateDate
Adatewhenthephotowasfirstuploaded.
Definition:public DateTime CreateDate
5.2.2.4 Property:Link
Thephotolink.
Definition:public Uri Link
5.2.2.5 Property:OwnerUserId
AFacebookuniqueidentifierofuserwhoownsthephoto.
Definition:public string OwnerUserId
5.2.2.6 Property:PhotoId
AFacebookuniqueidentifierofthephoto.
Definition:public string PhotoId
5.2.2.7 Property:Picture
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.
Definition:public Image Picture
5.2.2.8 Property:PictureUrl
Theurlofthispicture
Definition:public Uri PictureUrl
5.2.2.9 Property:PictureSmall
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.(smallversion)
Definition:public Image PictureSmall
5.2.2.10 Property:PictureSmallUrl
Theurlofthispicture(smallversion)
Definition:public Uri PictureSmallUrl
5.2.2.11 Property:PictureBig
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.(bigversion)
Definition:public Image PictureBig
5.2.2.12 Property:PictureBigUrl
Theurlofthispicture
Definition:public Uri PictureBigUrl
5.2.3
FacebookEventClass
ThisclassrepresentsaFacebookevent.
5.2.3.1 Property:Creator
TheFacebookidentifieroftheuserwhocreatedtheevent
Definition:public string Creator
5.2.3.2 Property:Description
Descriptionoftheevent
Definition:public string Description
5.2.3.3 Property:EndDate
Thedatethattheeventsends
Definition:public DateTime EndDate
5.2.3.4 Property:EventId
TheFacebookidentifieroftheevent.
Definition:public string EventId
5.2.3.5 Property:Host
TheFacebookuseridofthehostoftheevent
Definition:public string Host
5.2.3.6 Property:Location
Thenameoftheplacewheretheeventwilltakeplace.
Definition:public string Location
5.2.3.7 Property:Name
Thenameoftheevent
Definition:public string Name
5.2.3.8 Property:NetworkId
TheFacebookidentifierofthenetworkthatthiseventisapartof
Definition:public string NetworkId
5.2.3.9 Property:Picture
Theactualimageassociatedwiththeevent.Accessingthispropertywilldownloadthe
bytesoftheimageandserializeintoanimage.Thisdoesrequireasmallperformancehit.
5.2.3.10 Property:PictureUrl
Theurlofthiseventspicture
Definition:public Uri PictureUrl
5.2.3.11 Property:StartDate
Thedateandtimewhentheeventstarts
Definition:public DateTime StartDate
5.2.3.12 Property:SubType
Theseconarygroupofeventtype.
Definition:public string SubType
5.2.3.13 Property:TagLine
Thetaglineoftheeventifonewasspecified
Definition:public string TagLine
5.2.3.14 Property:Type
Theprimarygroupingoftheevent
Definition:public string Type
5.2.3.15 Property:UpdateDate
TheFacebookuseridofthepersonwhocreatedthealbum
Definition:public DateTime UpdateDate
5.2.4
GroupClass
ThisclasscontainsrepresentsaFacebookgroup.
5.2.4.1 Property:Creator
TheFacebookidentifieroftheuserwhocreatedthegroup
Definition:public string Creator
5.2.4.2 Property:Description
Thedescriptionofthegroup
Definition:public string Description
5.2.4.3 Property:GroupId
TheFacebookidentifierofthegroup
Definition:public string GroupId
5.2.4.4 Property:Name
Theuserenterednameofthegroup
Definition:public string Name
5.2.4.5 Property:NetworkId
TheFacebookidentifierofthenetworkthatthegroupispartof
Definition:public string NetworkId
5.2.4.6 Property:Office
Theaddressofthegroupsofficeifithasone.
Definition:public string Office
5.2.4.7 Property:Picture
Theactualimageassociatedwiththegroup.Accessingthispropertywilldownloadthe
bytesoftheimageandserializeintoanimage.Thisdoesrequireasmallperformancehit.
Definition:public Image Picture
5.2.4.8 Property:PictureUrl
Theurlofthisgroupspicture
Definition:public Uri PictureUrl
5.2.4.9 Property:RecentNews
Freeformtextdescribingrecentnewsassociatedwiththegroup
Definition:public string Recent News
5.2.4.10 Property:SubType
Theseconarygroupofgrouptype.
Definition:public string SubType
5.2.4.11 Property:Type
Theprimarygroupingoftheevent
Definition:public string Type
5.2.4.12 Property:UpdateDate
Thelastdateandtimethatchangesweremadetothegroup
Definition:public DateTime UpdateDate
5.2.4.13 Property:Venue
Thenameofthevenuewherethegroupmeetingsoccur
Definition:public string Venue
5.2.4.14 Property:WebSite
Theurlofthewebsiteforthegroup.
Definition:public string WebSite
5.2.5
GroupUserClass
ThisclasscontainsrepresentsaFacebookgroup.
5.2.5.1 Property:GroupId
TheFacebookidentifierofthegroup
Definition:public string GroupId
5.2.5.2 Property:Positions
Collectionofpositionsheldbythisuser
Definition:public Collection<GroupPosition> Positions
5.2.5.3 Property:User
Theuserobjectrepresentingtheprofileoftheuser
Definition:public User User
5.2.5.4 Property:UserId
TheFacebookidentifiedoftheuser
Definition:public string UserId
5.2.6
UserClass
ThisclasscontainsrepresentsaFacebookuser.
5.2.6.1 Property:AboutMe
Astringdescribingtheuser.Freeform.
5.2.6.2 Property:Activities
Freeformtextdescribingtheactivitiesthisuserisinterestedin.
Definition:public string Activities
5.2.6.3 Property:Affiliations
AcollectionofNetworksthisuserbelongsto
Definition:public Collection<Network> Affiliations
5.2.6.4 Property:Birthday
Thedaythisuserwasborn
Definition:public DateTime? Birthday
5.2.6.5 Property:Books
Freeformtextdescribingthisusersfavoritebooks
Definition:public string Books
5.2.6.6 Property:CurrentLocation
Thecurrentlocationfortheuser
Definition:public Location CurrentLocation
5.2.6.7 Property:FirstName
Theusersfirstname
Definition:public string FirstName
5.2.6.8 Property:HometownLocation
Thelocationoftheusershometown
Definition:public Location HometownLocation
5.2.6.9 Property:InterestedInGenders
Acollectioncontainingenumvaluesrepresentingthegendersthatthispersonis
interestedin.
Definition:public Collection<Gender> InterestedInGenders
5.2.6.10 Property:Interests
Freeformtextdescribingtheusersinterests
5.2.6.11 Property:InterestedInRelationshipTypes
Acollectioncontainingenumvaluesrepresentingthetypesofrelationshipsthatthis
personisinterestedin.
Definition:public Collection<LookingFor> InterstedInRelationshipTypes
5.2.6.12 Property:LastName
Theuserslastname
Definition:public string LastName
5.2.6.13 Property:Movies
Freeformtextdescribingtheusersfavoritemovies
Definition:public string Movies
5.2.6.14 Property:Music
Freeformtextdescribingtheusersfavoritemusic
Definition:public string Music
5.2.6.15 Property:Name
Theusersname
Definition:public string Name
5.2.6.16 Property:NotesCount
ThenumberofnotesthisuserhasassociatedwiththeirFacebookaccount.
Definition:public int NotesCount
5.2.6.17 Property:Picture
Theactualimageassociatedwiththisusersprofile.Accessingthispropertywilldownload
thebytesoftheimageandserializeintoanimage.Thisdoesrequireasmallperformance
hit.
Definition:public Image Picture
5.2.6.18 Property:PictureUrl
TheurlofthisusersFacebookpicture
Definition:public Uri PictureUrl
5.2.6.19 Property:PictureSmall
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.(smallversion)
Definition:public Image PictureSmall
5.2.6.20 Property:PictureSmallUrl
Theurlofthispicture(smallversion)
Definition:public Uri PictureSmallUrl
5.2.6.21 Property:PictureBig
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.(bigversion)
Definition:public Image PictureBig
5.2.6.22 Property:PictureBigUrl
Theurlofthispicture
Definition:public Uri PictureBigUrl
5.2.6.23 Property:PictureSquare
Theactualimage.Accessingthispropertywilldownloadthebytesoftheimageand
serializeintoanimage.Thisdoesrequireasmallperformancehit.(bigversion)
Definition:public Image PictureBig
5.2.6.24 Property:PictureSquareUrl
Theurlofthispicture
Definition:public Uri PictureSquareUrl
5.2.6.25 Property:PoliticalView
Anenumvaluerepresentingtheuserspoliticalview
Definition:public PoliticalView PoliticalView
5.2.6.26 Property:Quotes
Freeformtextrepresentingtheusersfavoritequotes
Definition:public string Quotes
5.2.6.27 Property:RelationshipStatus
Anenumvaluerepresentingtheuserscurrentrelationshipstatus.
5.2.6.28 Property:Religion
FreeformtextrepresentingtheReligion
Definition:public string Religion
5.2.6.29 Property:SchoolHistory
Adataobjectrepresentingtheuserseducationhistory
Definition:public SchoolHistory SchoolHistory
5.2.6.30 Property:Sex
Theusersgender
Definition:public Gender Sex
5.2.6.31 Property:SignificantOtherId
TheFacebookuseridofthisuserssignificantother
Definition:public string SignificantOtherId
5.2.6.32 Property:TVShows
FreeformtextdescribingthisusersfavoriteTVShows
Definition:public string TVShows
5.2.6.33 Property:UserId
TheFacebookuniqueidentifieroftheuser
Definition:public string UserId
5.2.6.34 Property:WallCount
Thenumberofmessagesthathavebeenwrittenonthisuserswall.
Definition:public int WallCount
5.2.6.35 Property:RelationshipStatus
TheFacebookidentifiedoftheuser
Definition:public RelationshipStatus RelationshipStatus
5.2.6.36 Property:Status
Dataobjectrepresentingtheuserscurrentstatus.Thisobjecthasmessageandtime
properties
5.2.6.37 Property:ProfileUpdateDate
Thedateandtimeofthelasttimethisuserchangedtheirprofile.
Definition:public DateTime ProfileUpdateDate
5.2.6.38 Property:WorkHistory
CollectionofWorkobjectrepresentingthisusersemploymenthistory
Definition:public Collection<Work> WorkHistory
5.2.7
SchoolHistoryClass
ThisclasscontainsFacebookuserseducationhistory(includinghighschoolandcollege).
5.2.7.1 Property:HigherEducaton
AcollectionofHigherEducationobjectrepresentingthecollegesthisuserattended.
Definition:public Collection<HigherEducation> HigherEducation
5.2.7.2 Property:HighSchool
AHighSchooldataobjectcontaininginformationaboutthehighschoolsthisuser
attended.
Definition: public HighSchool HighSchool
5.2.8
HighSchoolClass
Thisclassscontainsinformationaboutthehighschoolsthisuserattended.
5.2.8.1 Property:GraduationYear
Theyearthisusergraduatedfromcollege
Definition:public int GraduationYear
5.2.8.2 Property:HighSchoolOneId
TheFacebookuniqueidentifierofthehighschool
Definition:public string HighSchoolOneId
5.2.8.3 Property:HighSchoolOneName
Thenameofthehighschool
Definition:public string HighSchoolOneName
5.2.8.4 Property:HighSchoolTwoId
TheFacebookuniqueidentifierofthehighschool
Definition:public string HighSchoolTwoId
5.2.8.5 Property:HighSchoolTwoName
Thenameofthehighschool
Definition:public string HighSchoolTwoName
5.2.9
HigherEducationClass
ThisclasscontainsFacebookuserscollegeeducationhistory.
5.2.9.1 Property:AttendedFor
Anenumvaluerepresentingiftheschoolwasattendedforundergraduateworkor
graduatework
Definition:public SchoolType AttendedFor
5.2.9.2 Property:ClassYear
Graduationyear
Definition:public int ClassYear
5.2.9.3 Property:Concentration
Acollectiondescribingusersmajors
Definition:public Collection<string> Concentration
5.2.9.4 Property:School
Thenameoftheschool
Definition:public string School
5.2.10 NetworkClass
ThisclasscontainstheinformationaboutaFacebookNetwork.
5.2.10.1 Property:Name
Thenameofthenetwork.
Definition:public string Name
5.2.10.2 Property:NetworkId
TheFacebookuniqueidentifierofthenetwork.
5.2.10.3 Property:Status
Thestatusofthenetwork(OpenorClosed).
Definition:public string Status
5.2.10.4 Property:Type
Anenumvaluerepresentingthetypeofthenetwork(College,HighSchool,Workor
Region)
Definition:public NetworkType Type
5.2.10.5 Property:Year
Theyearassociatedwiththenetwork.
Definition:public int Year
5.2.11 LocationClass
Thisclasscontainsinformationaboutageographiclocation.
5.2.11.1 Property:City
Acityofthelocation.
Definition:public string City
5.2.11.2 Property:Country
Acountryofthelocation.
Definition:public Country Country
5.2.11.3 Property:State
Astateofthelocation.
Definition:public State State
5.2.11.4 Property:StateAbbreviation
Apostalabbreviationofthestateofthelocation.
Definition:public StateAbbreviation StateAbbreviation
5.2.11.5 Property:ZipCode
Azipcodeofthelocation.
5.2.12 WorkClass
ThisclasscontainsFacebookusersworkhistory.
5.2.12.1 Property:CompanyName
Thenameofthecompany.
Definition:public string CompanyName
5.2.12.2 Property:Description
Thedescriptionofjob.
Definition:public string Description
5.2.12.3 Property:EndDate
Thedatethattheuserendedthisemployment.
Definition:public DateTime EndDate
5.2.12.4 Property:Location
Thelocationofthejob.
Definition:public Location Location
5.2.12.5 Property:Position
Theusersposition/title.
Definition:public string Position
5.2.12.6 Property:StartDate
Thedatetheuserstartedthejob.
Definition:public DateTime StartDate
6 CodeSnippets
6.1 WindowsForm:ApplicationSetup
Afterregisteringyourdesktopapplicationathttp://api.Facebook.com,youwillreceiveanAPIkey
andasecret.TostartutilizingtheFacebookAPI,youmustaddareferencetotheFacebook.dll.
DraganinstanceofFacebookServicefromthetoolbox.EnteryourAPIKeyandSecret.
6.2 WindowsForm:RetrievingFriends
TheFacebookServicecomponentcontainsmethodsthatwrapallofthemethodsoftheFacebook
DeveloperAPI.Thefollowingprovidesanexampleforgettingallthefriendsoftheloggedinuser.
ThismethodreturnsagenericcollectionofUserobjects.TheUserobjectisastronglytyped
representationofaFacebookUserprofile.
Visual C#
using System.Collections.Generic;
using System.Collections.ObjectModel;
6.3 WindowsForm:UtilizingtheFriendListControl
ThereareseveralWinFormcontrolsthatexercisetheFacebookService.Thissampleshowshowto
usetheFriendListcontrol.DragaFriendListfromtheToolboxtoyourform.(Thisassumesyou
havealreadyaddedtheFacebookServicecomponentandsetyourAPIkeyandsecret).Simplyset
theFriendspropertyoftheFriendListcontrol.
Visual C#
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Facebook.Controls;
friendList1.Friends = FacebookService1.GetFriends();
Visual Basic
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports Facebook.Controls
friendList1.Friends = FacebookService1.GetFriends()
6.4 WindowsForm:HookingaFriendListControltoaProfileControl
TheProfileControlisusedtodisplaythedetailedprofileinformationaboutaFacebookUser.This
sampleshowshowtohookuptheeventthataFriendwasselectedintheFriendListControland
populateaProfilecontrolonthesameform.
Visual C#
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Facebook.Controls;
Visual Basic
Dim friends As Collection(Of User) = FacebookService1.GetFriends()
friendList1.Friends = friends
profile1.User = friends(0)
AddHandler friendList1.FriendSelected, AddressOf
friendList1_FriendSelected
6.5 WebApplication:AuthenticationProcess
WebApplicationdevelopmentrequireswritingcodetohandle3userstates.
1. Ifwedonthaveanauth_token,redirecttotheFacebookhostedloginpage.
2. Ifwehaveanauth_token,startasessiononbehalfoftheuser.
3. StoretheuserssessioninformationformakingcallstotheFacebookservice.
Thefollowingshowsasimplepagethathandlesthese3states.
Visual C#
// ApplicationKey and Secret are acquired when you sign up for
_fbService.ApplicationKey = "bfeefa69afdfe81975f0d6136ace3009";
_fbService.Secret = "9b672d682e1d8befd06382953fc2615b";
_fbService.IsDesktopApplication = false;
string sessionKey = Session["Facebook_session_key"] as String;
string userId = Session["Facebook_userId"] as String;
// When the user uses the Facebook login page, the redirect back
here // will will have the auth_token in the query params
string authToken = Request.QueryString["auth_token"];
// We have already established a session on behalf of this user
if (!String.IsNullOrEmpty(sessionKey))
{
_fbService.SessionKey = sessionKey;
_fbService.UserId = userId;
}
// This will be executed when Facebook login redirects to our page
else if (!String.IsNullOrEmpty(authToken))
{
_fbService.CreateSession(authToken);
Session["Facebook_session_key"] = _fbService.SessionKey;
Session["Facebook_userId"] = _fbService.UserId;
Session["Facebook_session_expires"] = fbService.SessionExpires;
}
// Need to login
else
{
Response.Redirect(@"http://www.Facebook.com/login.php?api_key=" +
_fbService.ApplicationKey + @"&v=1.0\");
}
if (!IsPostBack)
{
// Use the FacebookService Component to populate Friends
MyFriendList.Friends = _fbService.GetFriends();
}
Visual Basic
Private _fbService As Facebook.Components.FacebookService = New
Facebook.Components.FacebookService()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
' ApplicationKey and Secret are acquired when you sign up for
_fbService.ApplicationKey = "7a399eeba47b0f5b2bfd88cc872ada4a"
_fbService.Secret = "fad3d3fbeb8571957c39e2792073b978"
_fbService.IsDesktopApplication = False
ReleaseNotes:
Version1.1:
AddedmethodstoFacebookServicetowraptheNotifications.getFacebookAPIcall.Addeda
newdataobject"Notifications"forwrappingtheresults.
AddedStatusandProfileUpdateDatetotheUserobject.Statuscontainstheuser'sFacebook
StatusMessageandtimewhenitwasupdated.ProfileUpdateDatecontainsthedatewhenthe
userlastupdatedtheirFacebookprofile.
AddedSetFMBLmethod.AlsocorrectGetRequestURLtocorrectlyencodetheformat.
AddedDirectFQLQuery.Asdesignedonf8wiki.
FixedGetFriendsAppUsers.AsdesignedonF8wiki.
FixedtoadderrorhandlingtoCountryparsinginLocationParser
Addedimplementationsof2notificationsand2feedsapis.
Fixedparametersortingforfeedsapistoworkcorrectly.
ChangeRESTCallfromGETtoPOST.
AddGetLoggedInUser
Fixhandlingfornoreturnedsecret
AddoverloadtoGetUserInfothattakesaCollectionofuserids
Version1.2:
RefactoredFacebookService
AddedAsyncFacebookService
RefactoredParsersandEntitiesintotheirowndirectoryandnamespace
Addedimprovedphotoapi
AddedCanvasBasepagestoFacebook.WebControls
AddedCanvassamplestoFacebook.WebControls
AddedIFrameAjaxsample
AddedIFrameSilverlightExample
UpdatedtonewnotificationsAPI**INTERFACECHANGE**
UpdatedPublishStoryandPublishActioninterfaces**INTERFACECHANGE**
UpdatedCreateAlbuminterfacetoreturncreatedAlbum**INTERFACECHANGE**
AddedSetFBMLoverridetakinginuserid
Addedsmallandbigpictureurlandbitmaptophotoanduser
AddedGetFriendsNonAppUsersmethod