Referencing to the following article :
I am creating a User Photo Albums Browser Using Facebook Graph API. Everything is working fine except the Pagination
. The issue is $facebook->api
not returning "previous" paging link.
Following is my code :
$params = array();
$params['offset'] = 0;
if (isset($_GET['offset']))
$params['offset'] = $_GET['offset']+25;
if (isset($_GET['limit']))
$params['limit'] = $_GET['limit'];
$params['fields'] = 'name,source,images';
$params = http_build_query($params, null, '&');
$album_photos = $facebook->api("/{$_GET['id']}/photos?$params");
if (isset($album_photos['paging'])) {
if (isset($album_photos['paging']['next'])) {
$next_url = parse_url($album_photos['paging']['next'], PHP_URL_QUERY) . "&id=" . $_GET['id'];
}
if (isset($album_photos['paging']['previous'])) {
$pre_url = parse_url($album_photos['paging']['previous'], PHP_URL_QUERY) . "&id=" . $_GET['id'];
}
}
Here if I am printing :
echo '<pre>';
print_r($$album_photos['paging']);
exit;
The resulting is showing link this :
[paging] => Array
(
[next] => https://graph.facebook.com/133750480034063/photos?fields=name,source,images&offset=0&limit=25&after=MzI0ODMwNTYwOTI2MDUz
)
Which means paging
array returning link only for next
not for previous
.
How can I get the previous
link.
Any help would be appreciated.
The resulting is showing link this :
[next] => https://graph.facebook.com/133750480034063/photos?
fields=name,source,images&offset=0&limit=25&after=MzI0ODMwNTYwOTI2MDUz
Which means paging array returning link only for next not for previous.
With an offset of 0, there obviously are no previous data sets to retrieve.
Facebook changed this end of last year, saying that they are now only returning previous/next URLs if there actually is more data to fetch. (Not for all connections, but some.)
And this is a good thing, because it saves developers from making another time-consuming HTTP request just to find out there is no more data.
So, use them if they are present and you need more data – and if they are not there, just do nothing.