You are here

function fb_devel_fbu_page in Drupal for Facebook 7.3

Same name and namespace in other branches
  1. 5.2 fb_devel.module \fb_devel_fbu_page()
  2. 5 fb_devel.module \fb_devel_fbu_page()
  3. 6.3 fb_devel.module \fb_devel_fbu_page()
  4. 6.2 fb_devel.module \fb_devel_fbu_page()

A page which tests function which work with facebook user ids

1 string reference to 'fb_devel_fbu_page'
fb_devel_menu in ./fb_devel.module

File

./fb_devel.module, line 470
Makes development with Drupal for Facebook much easier. Keep this module enabled until you're confident your app works perfectly.

Code

function fb_devel_fbu_page($fbu = NULL) {
  global $_fb, $_fb_app;
  if ($fbu) {

    // Uses FQL
    $info = fb_users_getInfo(array(
      $fbu,
    ), $_fb);
    $output = "<p>Debug FQL info about facebook id {$fbu} ({$info[0]['name']}):</p>\n";
    $output .= "<img src=http://graph.facebook.com/{$fbu}/picture></img>";
    $output .= "<pre>" . print_r($info[0], 1) . "</pre>";

    // Use new graph api
    $info = $_fb
      ->api($fbu, array(
      'metadata' => 1,
    ));
    $output .= "<p>Debug info about facebook id {$fbu} ({$info['name']}):</p>\n";
    $output .= "<img src=http://graph.facebook.com/{$fbu}/picture></img>";
    $output .= "<pre>" . print_r($info, 1) . "</pre>";
    foreach (array(
      'statuses',
    ) as $connection) {
      try {
        if ($data = $_fb
          ->api($fbu . '/' . $connection)) {
          $output .= "<p>{$connection}<pre>";
          $output .= print_r($data, 1);
          $output .= "</pre></p>\n\n";
        }
      } catch (FacebookApiException $e) {
        fb_log_exception($e, t('Failed to lookup %connection', array(
          '%connection' => $fbu . '/' . $connection,
        )));
      }
    }
    try {
      $friends = $_fb
        ->api($fbu . '/friends');

      //dpm($friends, "$fbu/friends returned");
      $items = array();
      foreach ($friends['data'] as $data) {
        $items[] = l($data['name'], "fb/devel/fbu/{$data['id']}");
      }
      if (count($items)) {
        $output .= "\n<p>Known friends:<ul><li>";
        $output .= implode("</li>\n  <li>", $items);
        $output .= "</li></ul></p>\n\n";
      }
    } catch (FacebookApiException $e) {
      fb_log_exception($e, t('Failed to lookup friends of facebook user %fbu', array(
        '%fbu' => $fbu,
      )));
    }
    if (module_exists('fb_user')) {
      $local_friends = fb_user_get_local_friends($fbu);
      $items = array();
      foreach ($local_friends as $uid) {
        $account = user_load($uid);
        $items[] = theme('username', $account);
      }
      if (count($items)) {
        $output .= "\n<p>Local friends:<ul><li>";
        $output .= implode("</li>\n  <li>", $items);
        $output .= "</li></ul></p>\n\n";
      }
    }
  }
  else {
    drupal_set_message(t("You have to specify a facebook user id."), 'error');
  }
  return $output;
}