Advertisement
ShawnsSpace

User Likes Optimized for Limited Server Rescources

Jan 27th, 2014
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // navigate users with url parameter offset for this test.
  2. // example.com/?offset=0 example.com/?offet=25
  3. // using this method to page the users likes ensures you are not making more than one api call on one php thus minimizing timeouts in curl.  2 api calls is 2 curl requests.
  4. //$id is the user id
  5. //$fields is the information to get: first_name, last_name, friends, likes...
  6. //$facebook is the object obtained from: $facebook = new Facebook($config)
  7.   function get_user_info($id, $fields, $facebook)  {
  8.     try {
  9.         //$user_profile = $facebook->api('/'.$id.'?fields='.$fields,'GET');
  10.                if(!isset($_GET['offset'])){
  11.                     $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(0),'GET');
  12.               }
  13.               if($_GET['offset']==='25'){
  14.                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(25),'GET');
  15.                }elseif($_GET['offset']==='50'){
  16.                     $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(50),'GET');
  17.               }elseif($_GET['offset']==='75'){
  18.                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(75),'GET');
  19.                }elseif(isset(($_GET['offset']) && $_GET['offset']!='75' && $_GET['offset'!='50' && $_GET['offset']!='25'){
  20.                     $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(0),'GET');
  21.               }
  22.     } catch (FacebookApiException $e) {
  23.                //handle the exception
  24.         return NULL;
  25.     }
  26.  
  27.     return $user_profile;
  28.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement