Facebook Application DevelopmentSeptember 2009
AgendaIntroductionWhat Works for Brands?Measuring SuccessUnderstanding the “Viral Loop”The Facebook PlatformBuilding a Facebook ApplicationBuilding a Custom Facebook Fan PageBuilding a Facebook Connect Web PageReference Links
IntroductionWho is this guy and why is he Shiny?
Why I Am HereOver 40 campaigns on FacebookCo-Founded FacebookCamp (Toronto)Largest Facebook Dev Garage in the world!Co-Founded Refresh Partners in May 20071st Marketing Agency focused on Social NetworksFounded Shiny Agency in May 200910+ years as a marketing executive in public companies and startups10+ years as an engineering executive (and code-monkey) in startups
Previous Facebook Campaigns
Shiny AgencyWe are a specialized marketing agency focused on bringing brands to social networks, where their customers are.Using our experience, proven best-practices and utilizing only our local talent, we ensure that your project/campaign is successful.Queen Street West (near Spadina Ave), Toronto
What WORKS (& WHAT DOESN’T)How to get more 1 active user (you) …
Make It Socialable !
Target Your Audience3Cs Must Match your Target:CreativeCopyConcept
Allow Users to Interact With You
Entertain the User…
… or Provide Value
It Isn’t about Your BrandCan you find                  ?
… or It is All About Your Brand2,102,598 fans!
Keep Them Engaged (& Coming Back)
Be Different (& Unique)
Facebook Isn’t Your Microsite
(Your Graphic Designers are Gods, but) Don’t Reinvent the Look & Feelhttp://wiki.developers.facebook.com/index.php/DesignerNotes
Measuring SuccessNumbers keeps your boss happy
Vital MetricsStandard Web AnalyticsPageviews, Time-on-Site, GeographyRich DemographicsGender, Age, …Viral Coefficient (k-factor)For every new user, how manyother users do they bring in?
Social Network MetricsActive UsersHow many users have actually engaged with your application in the last week/month?Engagement MetricsReach and effectiveness of Newsfeeds, Notifications, Profile BoxesReferralsFrom Your Facebook presence to your web site
Understanding the Viral LoopThis is the key
Master the Viral LoopReach out to new users (newsfeeds/stream/profile)Bring users back often (events/notifications)Be interesting and have eye-candy (text copy & images)Insert your message everywhere (profile/newsfeed)Entice them to share your message
Social Ads are the Tip of The Viral Loop
Advertising in Other Applications
Application Directory
Your Fan Page
User’s ProfileMany Touch PointsWall & Newsfeed
Publisher
Profile Boxes
Narrow
Wide
Main
Profile Tab
Info Tab
Wall Attachments28
NotificationsBased on actions that the user completesBased on what their friend’s actionsBased on regular daily/weekly information updatesRemind them to come back
Invitations
Newsfeeds
Newsfeeds
Facebook PlatformKind of like the web (IE6 is still a problem)
Similar, but DifferentFacebook PlatformFBML / XFBMLFQLFBJSCSSFB-APIOpen StandardsHTMLSQLJavaScriptCSS
FBMLAccess to Facebook data<fb:nameuid="696646180" />turnsinto <a href="http://www.new.facebook.com/profile.php?id=696646180”>Roy Pereira</a>Use Facebook Design Elements<fb:tab-tem>35
FQLSQL-like interface to access Facebook dataDuplicate of API functionalityMany API functions are just FQL wrappersDon’t bother…
Facebook APIRESTAPI to access FacebookMost common uses are:get the User’s Friend listset Profile BoxesSend NotificationGet User’s InformationLots of client libraries:PHP, Java, .NET, RoRAPI keeps changing…37
API Test Toolhttp://developers.facebook.com/tools.php38
FBJSLike JavaScript, except…FBJS runs in a protected sandboxUses GETters and SETersBuilt-in Ajax & Animation
Building a Facebook ApplicationRemember your first time?
Setting up The Application	Add the Developer Applicationhttp://www.facebook.com/developers/apps.phpAdd an Application
Critical Configuration Fields
Finally…
InfrastructureDownload the Facebook API clienthttp://wiki.developers.facebook.com/index.php/Client_LibrariesSetup your hosting server	Facebook does not provider hosting!
Coding; Hello <user name><?php$api_key = '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);// Only for running on a Canvas page in an application$facebook->require_frame();// Only for non-public Canvas pages$facebook_user_id= $facebook->require_login();echo “<fbml>”;	// completely optionalecho “Hello <fb:nameuid=\”$facebook_user_id\”/> !”;echo “</fbml>”;
Coding; Friend’s Pictures<?php$api_key = '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);$facebook->require_frame();$facebook_user_id = $facebook->require_login();try {	$friends = $facebook->api_client->friends_get();} catch (FacebookRestClientException $ex) {}foreach($friends as $friend)	echo “<fb:profile-picuid=\”$friend\”/>”;http://wiki.developers.facebook.com/index.php/Friends.get
Coding; Registering Newsfeeds$one_line = array('{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href=”{*appurl*}">Toronto International Film Festival</a>.’);$short_story = array(	array(		'template_title' => '{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href=”{*appurl*}">Toronto International Film Festival</a>.',	'template_body' => 'Want to go with them?'	));$full_story = array(	array(		'template_title' => '{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href="' . APP_URL . '">Toronto International Film Festival</a>.',	'template_body' => 'Want to go with them?’	));$action_links = array(array('text' => 'Check out the movie!', 'href' => APP_URL));$feed_id =$facebook->api_client->feed_registerTemplateBundle(	$one_line, $short_story, $full_story, $action_links);http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle
Feed Preview Console48http://developers.facebook.com/tools.php?feed
Coding; Sending a Newsfeed (FBJS)<script type=“text/javascript”>function send_newsfeed(feed_id, movie, url, image){varmsg = 'Tell your friends about the TIFF app';var body = ’The best new movies!';vartemplate_data = {		"url":url,		"movie":movie,		"images":[	{				"src":image, 				"href":”http://apps.facebook.com/torontofilmfestival/”			}	]	};Facebook.showFeedDialog(feed_id, template_data, body, '', null, msg, '');}</script>http://wiki.developers.facebook.com/index.php/Facebook.showFeedDialog
Sending a Newsfeed
Coding; Setting the Profile Boxes$boxes = ‘<fb:wide>This is the wide box (388px wide)</fb:wide>’;$boxes .= ‘<fb:narrow>This is the narrow box (184px wide)</fb:narrow>’;$boxes .= ‘<fb:mobile>This only shows on the mobile website</fb:mobile>’;$main = ‘This is the main box on the wall tab of the profile (184px wide, 250px tall).  Very similar to the narrow box.’;$facebook->api_client->profile_setFBML(	null, 				// deprecated$facebook_user_id, $boxes, null, 				// deprecated	null,				// deprecated $main);<fb:add-section-button section=“profile”/>http://wiki.developers.facebook.com/index.php/Profile.setFBML
Coding; Sending App Notifications$users = array(123, 456, 789);$msg = ‘Hey, come back to the application.  Please?’;$msg_type = ‘app_to_user’;try {	$facebook->api_client->notifications_send($users, $msg, $msg_type);} catch (FacebookRestClientException $ex) {}http://wiki.developers.facebook.com/index.php/Notifications.send
Coding; Getting a User’s Information$users = array(123, 456, 789);$fields = array(	‘uid’,	‘name’,	‘birthday’,	‘sex’);try {	$info = $facebook->api_client->users_getInfo($users, $fields);} catch (FacebookRestClientException $ex) {}Warning; You can only keep this information for 24 hours (Facebook ToS)http://wiki.developers.facebook.com/index.php/Users.getInfo
Coding; FBJS Ajax<script>varinput_value = document.getElementById(‘myinput’).getValue();varajax = new Ajax();ajax.responseType = Ajax.FBML;ajax.onerror= function(){};ajax.ondone= function(data){document.getElementById(‘results’).setInnerFBML(data);	};ajax.post(‘http://apps.shinyagency.com/tiff/ajax.php’, ‘value=‘ + escape(input_value));</script>http://wiki.developers.facebook.com/index.php/FBJS
Important FB URL Variablesfb_sig_userUser IDfb_sig_profile_userProfile User ID (only available in a profile tab)fb_sig_localeUser’s language (en_US)installedEquals 1 the first time that the user adds your appfb_page_idThe page ID if the user is using the application on that Fan Page’s application tabhttp://wiki.developers.facebook.com/index.php/Your_callback_page_and_you
Building a Custom Fan PageKeep your fans on your page
Setting up the FB Application
Add the Application to the Fan PageGo to your Facebook applicationClick on the link besides 'Built By' at the bottom of the page  This will take you to the Fan Page of that applicationClick on Add to my Page (you may need to click on 'More' first)Select your Fan Page to add this app to
Coding; Support the Profile Tab<?php$api_key = '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);$facebook_user_id= $_REQUEST[‘fb_sig_profile_user’];if ($facebook_user_id)	echo “Hello <fb:nameuid=\”$facebook_user_id\”/>. Thanks for the info.”;$page_id = $_REQUEST[‘fb_page_id’];You do NOT know who the viewing user is (until they submit a form/ajax)!No auto-play JS/SWF.  No <fb:iframe> tag.Watch your <a href>; make them absolute.
Integrating Facebook ConnectMake the web social
FB Connect: Setup Application
FB Connect: XFBMLCreate xd_receiver.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head>	<title>Cross-Domain Receiver Page</title></head><body><script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2" type="text/javascript">	</script></body></html>http://wiki.developers.facebook.com/index.php/XFBML

Shiny Agency's Facebook Development Guidelines

  • 1.
  • 2.
    AgendaIntroductionWhat Works forBrands?Measuring SuccessUnderstanding the “Viral Loop”The Facebook PlatformBuilding a Facebook ApplicationBuilding a Custom Facebook Fan PageBuilding a Facebook Connect Web PageReference Links
  • 3.
    IntroductionWho is thisguy and why is he Shiny?
  • 4.
    Why I AmHereOver 40 campaigns on FacebookCo-Founded FacebookCamp (Toronto)Largest Facebook Dev Garage in the world!Co-Founded Refresh Partners in May 20071st Marketing Agency focused on Social NetworksFounded Shiny Agency in May 200910+ years as a marketing executive in public companies and startups10+ years as an engineering executive (and code-monkey) in startups
  • 5.
  • 6.
    Shiny AgencyWe area specialized marketing agency focused on bringing brands to social networks, where their customers are.Using our experience, proven best-practices and utilizing only our local talent, we ensure that your project/campaign is successful.Queen Street West (near Spadina Ave), Toronto
  • 7.
    What WORKS (&WHAT DOESN’T)How to get more 1 active user (you) …
  • 8.
  • 9.
    Target Your Audience3CsMust Match your Target:CreativeCopyConcept
  • 10.
    Allow Users toInteract With You
  • 11.
  • 12.
  • 13.
    It Isn’t aboutYour BrandCan you find ?
  • 14.
    … or Itis All About Your Brand2,102,598 fans!
  • 15.
    Keep Them Engaged(& Coming Back)
  • 16.
  • 17.
  • 18.
    (Your Graphic Designersare Gods, but) Don’t Reinvent the Look & Feelhttp://wiki.developers.facebook.com/index.php/DesignerNotes
  • 19.
  • 20.
    Vital MetricsStandard WebAnalyticsPageviews, Time-on-Site, GeographyRich DemographicsGender, Age, …Viral Coefficient (k-factor)For every new user, how manyother users do they bring in?
  • 21.
    Social Network MetricsActiveUsersHow many users have actually engaged with your application in the last week/month?Engagement MetricsReach and effectiveness of Newsfeeds, Notifications, Profile BoxesReferralsFrom Your Facebook presence to your web site
  • 22.
    Understanding the ViralLoopThis is the key
  • 23.
    Master the ViralLoopReach out to new users (newsfeeds/stream/profile)Bring users back often (events/notifications)Be interesting and have eye-candy (text copy & images)Insert your message everywhere (profile/newsfeed)Entice them to share your message
  • 24.
    Social Ads arethe Tip of The Viral Loop
  • 25.
  • 26.
  • 27.
  • 28.
    User’s ProfileMany TouchPointsWall & Newsfeed
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
    NotificationsBased on actionsthat the user completesBased on what their friend’s actionsBased on regular daily/weekly information updatesRemind them to come back
  • 38.
  • 39.
  • 40.
  • 41.
    Facebook PlatformKind oflike the web (IE6 is still a problem)
  • 42.
    Similar, but DifferentFacebookPlatformFBML / XFBMLFQLFBJSCSSFB-APIOpen StandardsHTMLSQLJavaScriptCSS
  • 43.
    FBMLAccess to Facebookdata<fb:nameuid="696646180" />turnsinto <a href="http://www.new.facebook.com/profile.php?id=696646180”>Roy Pereira</a>Use Facebook Design Elements<fb:tab-tem>35
  • 44.
    FQLSQL-like interface toaccess Facebook dataDuplicate of API functionalityMany API functions are just FQL wrappersDon’t bother…
  • 45.
    Facebook APIRESTAPI toaccess FacebookMost common uses are:get the User’s Friend listset Profile BoxesSend NotificationGet User’s InformationLots of client libraries:PHP, Java, .NET, RoRAPI keeps changing…37
  • 46.
  • 47.
    FBJSLike JavaScript, except…FBJSruns in a protected sandboxUses GETters and SETersBuilt-in Ajax & Animation
  • 48.
    Building a FacebookApplicationRemember your first time?
  • 49.
    Setting up TheApplication Add the Developer Applicationhttp://www.facebook.com/developers/apps.phpAdd an Application
  • 50.
  • 51.
  • 52.
    InfrastructureDownload the FacebookAPI clienthttp://wiki.developers.facebook.com/index.php/Client_LibrariesSetup your hosting server Facebook does not provider hosting!
  • 53.
    Coding; Hello <username><?php$api_key = '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);// Only for running on a Canvas page in an application$facebook->require_frame();// Only for non-public Canvas pages$facebook_user_id= $facebook->require_login();echo “<fbml>”; // completely optionalecho “Hello <fb:nameuid=\”$facebook_user_id\”/> !”;echo “</fbml>”;
  • 54.
    Coding; Friend’s Pictures<?php$api_key= '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);$facebook->require_frame();$facebook_user_id = $facebook->require_login();try { $friends = $facebook->api_client->friends_get();} catch (FacebookRestClientException $ex) {}foreach($friends as $friend) echo “<fb:profile-picuid=\”$friend\”/>”;http://wiki.developers.facebook.com/index.php/Friends.get
  • 55.
    Coding; Registering Newsfeeds$one_line= array('{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href=”{*appurl*}">Toronto International Film Festival</a>.’);$short_story = array( array( 'template_title' => '{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href=”{*appurl*}">Toronto International Film Festival</a>.', 'template_body' => 'Want to go with them?' ));$full_story = array( array( 'template_title' => '{*actor*} is going to see <a href="{*url*}">{*movie*}</a> during the <a href="' . APP_URL . '">Toronto International Film Festival</a>.', 'template_body' => 'Want to go with them?’ ));$action_links = array(array('text' => 'Check out the movie!', 'href' => APP_URL));$feed_id =$facebook->api_client->feed_registerTemplateBundle( $one_line, $short_story, $full_story, $action_links);http://wiki.developers.facebook.com/index.php/Feed.registerTemplateBundle
  • 56.
  • 57.
    Coding; Sending aNewsfeed (FBJS)<script type=“text/javascript”>function send_newsfeed(feed_id, movie, url, image){varmsg = 'Tell your friends about the TIFF app';var body = ’The best new movies!';vartemplate_data = { "url":url, "movie":movie, "images":[ { "src":image, "href":”http://apps.facebook.com/torontofilmfestival/” } ] };Facebook.showFeedDialog(feed_id, template_data, body, '', null, msg, '');}</script>http://wiki.developers.facebook.com/index.php/Facebook.showFeedDialog
  • 58.
  • 59.
    Coding; Setting theProfile Boxes$boxes = ‘<fb:wide>This is the wide box (388px wide)</fb:wide>’;$boxes .= ‘<fb:narrow>This is the narrow box (184px wide)</fb:narrow>’;$boxes .= ‘<fb:mobile>This only shows on the mobile website</fb:mobile>’;$main = ‘This is the main box on the wall tab of the profile (184px wide, 250px tall). Very similar to the narrow box.’;$facebook->api_client->profile_setFBML( null, // deprecated$facebook_user_id, $boxes, null, // deprecated null, // deprecated $main);<fb:add-section-button section=“profile”/>http://wiki.developers.facebook.com/index.php/Profile.setFBML
  • 60.
    Coding; Sending AppNotifications$users = array(123, 456, 789);$msg = ‘Hey, come back to the application. Please?’;$msg_type = ‘app_to_user’;try { $facebook->api_client->notifications_send($users, $msg, $msg_type);} catch (FacebookRestClientException $ex) {}http://wiki.developers.facebook.com/index.php/Notifications.send
  • 61.
    Coding; Getting aUser’s Information$users = array(123, 456, 789);$fields = array( ‘uid’, ‘name’, ‘birthday’, ‘sex’);try { $info = $facebook->api_client->users_getInfo($users, $fields);} catch (FacebookRestClientException $ex) {}Warning; You can only keep this information for 24 hours (Facebook ToS)http://wiki.developers.facebook.com/index.php/Users.getInfo
  • 62.
    Coding; FBJS Ajax<script>varinput_value= document.getElementById(‘myinput’).getValue();varajax = new Ajax();ajax.responseType = Ajax.FBML;ajax.onerror= function(){};ajax.ondone= function(data){document.getElementById(‘results’).setInnerFBML(data); };ajax.post(‘http://apps.shinyagency.com/tiff/ajax.php’, ‘value=‘ + escape(input_value));</script>http://wiki.developers.facebook.com/index.php/FBJS
  • 63.
    Important FB URLVariablesfb_sig_userUser IDfb_sig_profile_userProfile User ID (only available in a profile tab)fb_sig_localeUser’s language (en_US)installedEquals 1 the first time that the user adds your appfb_page_idThe page ID if the user is using the application on that Fan Page’s application tabhttp://wiki.developers.facebook.com/index.php/Your_callback_page_and_you
  • 64.
    Building a CustomFan PageKeep your fans on your page
  • 65.
    Setting up theFB Application
  • 66.
    Add the Applicationto the Fan PageGo to your Facebook applicationClick on the link besides 'Built By' at the bottom of the page  This will take you to the Fan Page of that applicationClick on Add to my Page (you may need to click on 'More' first)Select your Fan Page to add this app to
  • 67.
    Coding; Support theProfile Tab<?php$api_key = '7483ff2c054d8116197fbb54f1893fab';$secret = 'e13ede6fc6eec92e4aac48e4aa586391';$facebook = new Facebook($api_key, $secret);$facebook_user_id= $_REQUEST[‘fb_sig_profile_user’];if ($facebook_user_id) echo “Hello <fb:nameuid=\”$facebook_user_id\”/>. Thanks for the info.”;$page_id = $_REQUEST[‘fb_page_id’];You do NOT know who the viewing user is (until they submit a form/ajax)!No auto-play JS/SWF. No <fb:iframe> tag.Watch your <a href>; make them absolute.
  • 68.
  • 69.
  • 70.
    FB Connect: XFBMLCreatexd_receiver.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head> <title>Cross-Domain Receiver Page</title></head><body><script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2" type="text/javascript"> </script></body></html>http://wiki.developers.facebook.com/index.php/XFBML
  • 71.
    FB Connect: XFBMLAddsupport for XFBML to your pageLoad the JS client libraryInitialize the client library<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script><script type="text/javascript">FB_RequireFeatures([”Connect"], function(){FB.init("YOUR_API_KEY_HERE", "<relative path from root>/xd_receiver.htm {"ifUserConnected":fb_connected, "ifUserNotConnected":fb_not_connected});});</script> http://wiki.developers.facebook.com/index.php/XFBML
  • 72.
    FB Connect: Login<fb:login-buttononlogin=“return fb_login();“></fb:login-button><script>function facebook_login(){FB.Connect.requireSession(function() { fb_connected(); });}function fb_connected(){varuid = FB.Connect.get_loggedInUser();varapi = new FB.ApiClient(api_key);api.users_getInfo([uid],['name,current_location'], function(data) {document.getElementById('uid_info').innerHTML = uid + '<br/>name: ' + data[0].name + ' from ' + data[0].current_location.city + ', ' + data[0].current_location.country + "<fb:profile-pic size=\"square\" uid=” + uid + "></fb:profile-pic>”; });return false;}</script>
  • 73.
    FB Connect: Logout<script>functionfb_logout(){FB.Connect.logout(function(bool){ return true; });}</script>
  • 74.
  • 75.
    FB Connect: RetrievingFriends<script>varapi = FB.Facebook.apiClient;api.friends_get(new Array(), function(result, exception){ // do something with result }); </script>
  • 76.
    Reference LinksI tellyou where to go…
  • 77.
  • 78.
    70Roy@ShinyAgency.com http://ShinyAgency.com