0

I'm using Symfony2 with HWIOAuthBundle. I managed to obtain requested data (including page likes), but if their number exceeds 24 and the user has more than 24 page likes facebook api sends next attribute with the URL to call as following:

...
    [24]=>
        array(4) {
          ["category"]=>
          string(26) "Computers/Internet Website"
          ["name"]=>
          string(10) "IOScreator"
          ["id"]=>
          string(16) "1488441341444225"
          ["created_time"]=>
          string(24) "2015-01-30T10:28:42+0000"
        }
      }
      ["paging"]=>
      array(2) {
        ["cursors"]=>
        array(2) {
          ["before"]=>
          string(20) "MTEyOTU3ODQ1NDAwNzAw"
          ["after"]=>
          string(24) "MTQ4ODQ0MTM0MTQ0NDIyNQ=="
        }
        ["next"]=>
        string(99) "https://graph.facebook.com/v2.0/10152896110784845/likes?limit=25&after=MTQ4ODQ0MTM0MTQ0NDIyNQ%3D%3D"
      }
    }

Does anybody know how to request the next page within this bundle?

Here is how I obtain the first response:

$userProvider = $this->container->get('bundleName_user.oauth_provider');
$facebookResourceOwner = $this->container->get('hwi_oauth.resource_owner.facebook');

$accessToken = $request->get('accessToken');
$userResponse = $facebookResourceOwner->getUserInformation(array(
    'access_token' => $accessToken
));
Jörn Hees
  • 3,338
  • 22
  • 44
peter
  • 147
  • 2
  • 13

1 Answers1

1

I don't think there is a way of doing it directly using the bundle but HWIOBundle but there are two ways I could see you doing this.

Option 1: Add to FacebookResourceOwner.php

In here you could add in another function to make a request, which would use the libraries contained within HWIOBundle. Something like:

public function nextParamRequest($access_token, $nextURL) {
  $response = $this->httpRequest($this->normalizeUrl($nextURL, array('access_token' => $access_token), array(), array())));

  return $this->getResponseContent($response);
}

Option 2: Just write your own cURL method to do it

Somewhere in your code just add the following:

function curlNextUrl($access_token, $nextURL) {
  $request_url = $nextURL."&access_token=".$access_token;

  $curl = curl_init();
  curl_setopt($curl, CURLOPT_URL, $request_url);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);    
  curl_setopt($curl, CURLOPT_HEADER, 0);

  $response = curl_exec($curl);
  curl_close($curl);

  return json_decode($response, true);
}
The1Fitz
  • 662
  • 4
  • 8