Guest User

get facebook user info

a guest
Jan 27th, 2014
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. //$id is the user id
  2. //$fields is the information to get: first_name, last_name, friends, likes...
  3. //$facebook is the object obtained from: $facebook = new Facebook($config)
  4.   function get_user_info($id, $fields, $facebook)  {
  5.     try {
  6.         $user_profile = $facebook->api('/'.$id.'?fields='.$fields,'GET');
  7.     } catch (FacebookApiException $e) {
  8.                 //handle the exception
  9.         return NULL;
  10.     }
  11.  
  12.         //handle with paged likes
  13.     if (array_key_exists('next',$user_profile['likes']['paging'])) {
  14.         $after = $user_profile['likes']['paging']['cursors']['after'];
  15.         try {
  16.             $new  = $facebook->api('/'.$id.'/likes?after=' . $after, 'GET');
  17.             $n = $new; //to get right 'after'
  18.             while(array_key_exists('next',$n['paging'])) {
  19.                 $after = $n['paging']['cursors']['after'];
  20.                 $n = $facebook->api('/'.$id.'/likes?after=' . $after, 'GET');
  21.                 $new = array_merge_recursive($new,$n);
  22.             }
  23.             $user_profile = array_merge_recursive($user_profile,array("likes"=>$new));
  24.             unset($user_profile['likes']['paging']);
  25.         } catch (FacebookApiException $e) {
  26.                       //...
  27.         }
  28.     }
  29.     return $user_profile;
  30.   }
Advertisement
Add Comment
Please, Sign In to add comment