I have been answering a lot of email requests for how to get started with a Bebo application. Since applications can be written in any language that supports interaction with the Bebo REST API, developers have a lot of choices in how they build their application. The focus of this article will be on the "officially supported language" - PHP. I saw officially supported, because the Bebo Platform Team has released a simple PHP wrapper that makes using the REST API very simple, and they update this from time to time.
Before creating an application, you need to understand the parts of an application and how they interact with Bebo. I will go over each part below, and then show an example of a very simple application that uses each part.
The Bebo URL - this is the URL that users go to on Bebo. It is in the format "http://apps.bebo.com/yourapp/"
The Callback URL - this is the URL on your server that Bebo redirects to. It is where the actual application lives.
The Canvas Page - this is the main page of a Bebo application. It takes up the entire web page, except for the Bebo top header and footer. User's going to your canvas page are using your server directly via the callback URL. Canvas pages can either be written in SNML, a markup language that is standardized across Facebook and Bebo and is fast to load, or in an iFrame. Javascript is only allowed in iFrame based applications, but they cannot use SNML.
The Profile Box - each application can create a presence on the installing user's Profile page. This contents of this box are set by the application, but when the user is seeing this Profile box, it is running a cached version on Bebo's servers. The user can click links or interact with Flash to go to the canvas page or call back to your server using simple AJAX. Since browsing other people's Profiles is one of the main activities on Bebo, creating a compelling Profile Box is a very important part of helping your application to spread.
Invitations - each application can provide a way for users to recommend it to their friends. Bebo provides a common dialog for selecting friends, and limits the total number of invitations that can be send per person per day. You can control some of the text that the inviter sees when selecting their friends, and some of the text in the actual invitation. Your application must give the user a reason to want to send an invitation, either by being innately good, or by some type of reward system for invited friends.
News Stories - applications can produce news stories based on how the users interact with the application. These stories appear on the user's Profile page in the news section. Bebo will also show the most interesting stories from a user's friends on their home page. News stories should be interesting and actionable in order to help your application spread and provide value to the user.
require_once "bebo.php";
$appVisibleName = "Example App"; $appApiKey = 'copy API Key from the developer application page'; $appSecret = 'copy API Secret from the developer application page'; $appCallback = 'put in your callback url. Ex - http://myserver.com/favoritebirds/ '; $appBeboURL = 'put in the Application URL above - http://apps.bebo.com/favoritebirds/';
$bebo = new Bebo( $appApiKey, $appSecret ); $userID = $bebo->require_add();
displayPage($bebo); function displayPage($bebo) { $userID = $bebo->user; $output = "Welcome back, <sn:name uid='$userID' useyou='false' />.<br/> You have a nice picture:<sn:profile-pic uid='$userID' linked='false'/>"; echo $output; }
You now have a fully functional Bebo application. But, let's add some more features.
updateProfile($bebo); function updateProfile($bebo) { global $appVisibleName; $userID = $bebo->user; $snml = "This is the $appVisibleName profile box of <sn:name uid='$userID' useyou='false' /> <br/><sn:profile-pic uid='$userID' size='square' linked='false'/>"; $bebo->api_client->profile_setSNML($snml); }
publishStory($bebo); function publishStory($bebo) { global $appVisibleName; global $appBeboURL; $actor = $bebo->user; $title_template = "{actor} used <a href='$appBeboURL'>$appVisibleName</a>"; $title_data = null; $body_template = null; $body_data = null; $body_general = "Everyone should try $appVisibleName. <a href='$appBeboURL'> Install $appVisibleName today.</a>"; $image1 = null; $image1Link = null; try { $result = $bebo->api_client->feed_publishTemplatizedAction( $actor, $title_template, $title_data, $body_template, $body_data, $body_general, $image1, $image1Link, NULL, NULL, NULL, NULL, NULL, NULL, ""); } catch( Exception $ex) { } }
$invitePageURL = getInvitePageURL($bebo); echo "<a href='$invitePageURL'>Would you like to invite some friends?</a>"; function getInvitePageURL($bebo) { global $appApiKey; global $appBeboURL; global $appVisibleName; $beboInvitePage = "http://www.bebo.com/multi_friend_selector.php"; // What the inviter sees $actionText = urlencode("Which friends do you want to invite?"); $action = $appBeboURL; $type = urlencode("Invite"); // What the recipient sees $acceptInviteButtonURL = $bebo->get_add_url($appBeboURL); $acceptInviteButtonLabel = "Add $appVisibleName"; $acceptInviteButton = "<sn:req-choice url='$acceptInviteButtonURL' label='$acceptInviteButtonLabel' />"; $content = urlencode("Hey, try out $appVisibleName. $acceptInviteButton"); $sig = 0; // update with the signature tool. This is a two step process. Generate the url for the invite page // Then go to http://www.bebo.com/AppToolSig.jsp and paste it in. At the bottom, you will get a signature. Update the value above. // If you change the invite text, you will have to regenerate the sig above $invitePageURL = "$beboInvitePage?sig=$sig&api_key=$appApiKey&content=$content&type=$type &action=$action&actiontext=$actionText&invite=true"; return $invitePageURL; }
Here is the completed sample:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <?php date_default_timezone_set("America/New_York"); require_once "bebo.php"; // Global definitions for your app $appVisibleName = "Favorite Birds"; $appApiKey = "copy API Key from the developer application page"; $appSecret = "copy API Secret from the developer application page"; $appCallback = "http://myserver.com/favoritebirds "; $appBeboURL = "http://apps.bebo.com/favoritebirds/"; ///Main Entry Point /// // Force everyone to add the application. // If they have already added it, then display the page $bebo = new Bebo( $appApiKey, $appSecret ); $userID = $bebo->require_add(); displayPage($bebo); // Update the user's profile updateProfile($bebo); // Publish a news story publishStory($bebo); ///End Main Entry Point /// function displayPage($bebo) { $userID = $bebo->user; $output = "Welcome back, <sn:name uid='$userID' useyou='false' />.<br/> You have a nice picture:<sn:profile-pic uid='$userID' linked='false'/>"; // Add the link to the invite page $invitePageURL = getInvitePageURL($bebo); $output .= "<br/><a href='$invitePageURL'>Would you like to invite some friends?</a>"; echo $output; } // returns the url for the Bebo standard invite page function getInvitePageURL($bebo) { global $appApiKey; global $appBeboURL; global $appVisibleName; $beboInvitePage = "http://www.bebo.com/multi_friend_selector.php"; // What the inviter sees $actionText = urlencode("Which friends do you want to invite?"); $action = $appBeboURL; $type = urlencode("Invite"); // What the recipient sees $acceptInviteButtonURL = $bebo->get_add_url($appBeboURL); $acceptInviteButtonLabel = "Add $appVisibleName"; $acceptInviteButton = "<sn:req-choice url='$acceptInviteButtonURL' label='$acceptInviteButtonLabel' />"; $content = urlencode("Hey, try out $appVisibleName. $acceptInviteButton"); $sig = 0; // update with the signature tool. This is a two step process. Generate the url for the invite page // Then go to http://www.bebo.com/AppToolSig.jsp and paste it in. At the bottom, you will get a signature. Update the value above. // If you change the invite text, you will have to regenerate the sig above $invitePageURL = "$beboInvitePage?sig=$sig&api_key=$appApiKey&content=$content&type=$type&action=$action&actiontext=$actionText&invite=true"; return $invitePageURL; } function updateProfile($bebo) { global $appVisibleName; $userID = $bebo->user; $snml = "This is the $appVisibleName profile box of <sn:name uid='$userID' useyou='false' /> <br/><sn:profile-pic uid='$userID' size='square' linked='false'/>"; $bebo->api_client->profile_setSNML($snml); } function publishStory($bebo) { global $appVisibleName; global $appBeboURL; $actor = $bebo->user; $title_template = "{actor} used <a href='$appBeboURL'>$appVisibleName</a>"; $title_data = null; $body_template = null; $body_data = null; $body_general = "Everyone should try $appVisibleName. <a href='$appBeboURL'>Install $appVisibleName today.</a>"; $image1 = null; $image1Link = null; try { $result = $bebo->api_client->feed_publishTemplatizedAction( $actor, $title_template, $title_data, $body_template, $body_data, $body_general, $image1, $image1Link, NULL, NULL, NULL, NULL, NULL, NULL, ""); } catch( Exception $ex) { } } ?>
The example above just forces everyone to add, but isn't able to specially handle new installs or removals. You can handle those by looking at the $_REQUEST parameters that Bebo passes your application. These parameters show that users come to your application in 1 of 3 states:
By changing the block marked ///Main Entry Point /// above to one that detects the state, you can handle each one differently. You will need to add new functions to handle new user installs and uninstalls
///Main Entry Point /// // An existing user will have the fb_sig_in_canvas variable set, unless they are removing if (isSet($_POST) && isSet($_POST['fb_sig_in_canvas'])) { // Bebo will pass their user id and that they have added the application if ( isSet($_POST['fb_sig_user']) && $_POST['fb_sig_added'] == 1 ) { $userID = $_POST['fb_sig_user']; // If the user has just installed, Bebo will pass installed as a GET parameter if ( isSet($_GET) && isSet($_GET['installed']) ) { newInstall($userID); } // Normal users will go through here, so display the page $bebo = new Bebo( $appApiKey, $appSecret ); displayPage($bebo); // Update the user's profile updateProfile($bebo); // Publish a news story publishStory($bebo); } } // If you set up your own post add handler, then you must handle the add request the way you want, // and then redirect back to your Bebo URL. If you don't specify a post add handler, Bebo does this for you. else if ( isSet($_GET) && isSet($_GET['installed']) ) { $bebo = new Bebo( $appApiKey, $appSecret ); newInstall($bebo ); $bebo->redirect($appBeboURL); } // If you specify a post remove URL, then Bebo will call it with this POST variable. // After this call, you won't get anything else from this user unless they re-add your application else if ( isSet($_POST) && isSet($_POST['fb_sig_uninstall']) ) { $userID = $_POST['fb_sig_user']; uninstallUser( $userID); } // If the user goes to your callback URL directly, they didn't come in from Bebo, and you will have no information about the user // In most cases, you will just want to force the user to add the application by using require_add. This will force them back through // the existing user path above else { $bebo = new Bebo( $appApiKey, $appSecret ); $bebo->require_add(); } // Handle a new user installation function newInstall($userID) { // We can use the SNML to say hello to the user $output = "Hello, <sn:name uid='$userID' useyou='false' />. Thanks for adding the application!"; echo $output; } function uninstallUser($userID) { // You can't actually display anything to the user, or redirect them. // All you can do is clean up inside your application. } ///End Main Entry Point ///
Thought Labs provides custom software development and consulting services with a specialization in Social Network technologies. We build branded Facebook Pages for your company or multiple Pages for your various products. In addition, we create rich interactive applications on your Page to help users find your products and services. Thought Labs can also create custom Facebook, Bebo or OpenSocial applications carrying your message and your brand with them.
We pride ourselves on the quality of our work. We employ top application developers who are creative, highly skilled, up-to-date on the Social Networks' constantly changing APIs, and excellent at project management. We set high standards for ourselves and we meet them. In this new world of social marketing, Thought Labs delivers extremely innovative, high-quality work on time and on budget. Find out more at https://www.thoughtlabs.com.com.