View difference between Paste ID: UryyucW0 and sJhK4xM6
SHOW: | | - or go back to the newest paste.
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-
  		$user_profile = $facebook->api('/'.$id.'?fields='.$fields,'GET');
6+
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-
        //handle with paged likes
12+
               }
13-
 	if (array_key_exists('next',$user_profile['likes']['paging'])) {
13+
               if($_GET['offset']==='25'){
14-
  		$after = $user_profile['likes']['paging']['cursors']['after'];
14+
                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(25),'GET');
15-
  		try {
15+
               }elseif($_GET['offset']==='50'){
16-
  			$new  = $facebook->api('/'.$id.'/likes?after=' . $after, 'GET');
16+
                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(50),'GET');
17-
  			$n = $new; //to get right 'after'
17+
               }elseif($_GET['offset']==='75'){
18-
  			while(array_key_exists('next',$n['paging'])) {
18+
                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(75),'GET');
19-
  				$after = $n['paging']['cursors']['after'];
19+
               }elseif(isset(($_GET['offset']) && $_GET['offset']!='75' && $_GET['offset'!='50' && $_GET['offset']!='25'){
20-
  				$n = $facebook->api('/'.$id.'/likes?after=' . $after, 'GET');
20+
                    $user_profile = $facebook->api('/'.$id.'?fields=id,name,likes.offset(0),'GET');
21-
  				$new = array_merge_recursive($new,$n);
21+
               }
22-
  			}
22+
23-
  			$user_profile = array_merge_recursive($user_profile,array("likes"=>$new));
23+
24-
  			unset($user_profile['likes']['paging']);
24+
25-
  		} catch (FacebookApiException $e) {
25+
26-
                      //...
26+
27-
  		}
27+
28
  }