Bebo Examples

Dec 20, 2011 Published by Tony Primerano

Display All My Friends

Simple PHP to display all your friends and links to their profiles. Note: if you are running your app as a iframe the sn:profile-pic tag will not work. You'll need to use the API to build the URL.

<?php
 require_once '../bebo-0.4.6.phplib';
 $bebo = new Bebo("your key" , "your secret");
 $friends =  $bebo->friends_get(); // get list of friends
 foreach ($friends as $friend) {
   print "<a href=\"/Profile.jsp?MemberId=$friend\"><sn:profile-pic uid=\"$friend\" size=\"n\" /> </a>";
 }
?>

Display All My Friends on my Profile

Same as last example but it calls profile_setFBML to put the markup on your profile page. This markup is ONLY updated when you visit the application page.

<?php
require_once '../bebo-0.4.6.phplib';
  $bebo = new Bebo("your key" , "your secret");
  $friends =  $bebo->friends_get(); // get list of friends
  $markup = "";
  foreach ($friends as $friend) {
    $markup .= "<a href=\"/Profile.jsp?MemberId=$friend\"><sn:profile-pic uid=\"$friend\" size=\"n\" /> </a>";
  }
  // Print markup to application screen
  print $markup;
  // Put markup on the profile
  $result = $bebo->profile_setFBML($markup, $bebo->get_loggedin_user());
  if ($result == "1") {
    print("<h2>The following friends have been added to your profile</h2>" . $photos);
    // Print markup to application screen
    print $markup;

  } else {
    print("<h2>An Error has occurred</h2>");
    var_dump($result);

  }
?>

Set a handle on a user's profile

This code puts the text "Dynamic Stuff =>" on a user's profile and when their handle is updated there will be new content after "Dynamic Stuff =>" string.

<?php
  require_once '../bebo-0.4.6.phplib';
  $bebo = new Bebo("your key" , "your secret");
  $handle = $bebo->get_loggedin_user();  //Unique handle per user
  $markup = "Dynamic Stuff => <sn:ref handle=\"" . $handle . "\"> </sn:ref>";
  // Put markup (just handle reference) on the profile
  $result = $bebo->profile_setFBML($markup, $bebo->get_loggedin_user());
  if ($result == "1") {
    print("Added handle to profile.");
  } else {
    print("<h2>An Error has occurred</h2>");
    var_dump($result);
  } 
?>

Update a handle on a user's profile

Create a new php file called update.php and place it in the same directory as your application index.php file. This file, when called via the Bebo proxy/application page will place the current time on the user's profile.

Example call.

<?php
  require_once '../bebo-0.4.6.phplib';
  $bebo = new Bebo("your key" , "your secret");

  $handle = $bebo->get_loggedin_user();  // use user's handle unless otherwise specified.
  if (array_key_exists('handle', $_REQUEST)) {
    if ( count($_REQUEST['handle'])>0) {
      $handle = $_REQUEST['handle'];
    }
  }
  // pretend we just pulled their feeds or something interesting
  $result = $bebo->api_client->fbml_setRefHandle($handle, "<h2>last updated at ". strftime('%c') ."</h2>");

  if ($result == "1") {
    print("Updated handle with ID of $handle");
  } else {
    print("<h2>An Error has occurred</h2>");
    var_dump($result);
  }
?>

Set a handle on a user's profile and use hidden image for update

This code puts the text "Dynamic Stuff =>" on a user's profile and when their handle is updated there will be new content after "Dynamic Stuff =>" string. We added an image tag that will force a refresh anytime the user views their profile. Unfortunately, it will only show the update after a refresh. If another user of the application views this person's page it will also refresh the content as all that is needed is a valid application user session for this code to fire.

<?php
  require_once '../bebo-0.4.6.phplib';
  $bebo = new Bebo("your key" , "your secret");
  $handle = $bebo->get_loggedin_user();  //Unique handle per user
  $markup = "Dynamic Stuff => <sn:ref handle=\"" . $handle . "\"> </sn:ref>";
  // Add the hidden image hack
  $markup .= "<img style=\"display:none\" src=\"http://apps.bebo.com/sample/refresh.php?handle=$handle\" /> ";

  // Put markup (just handle reference) on the profile
  $result = $bebo->profile_setFBML($markup, $bebo->get_loggedin_user());
  if ($result == "1") {
    print("Added handle to profile.");
  } else {
    print("<h2>An Error has occurred</h2>");
    var_dump($result);
  }
?>