在php中没有从facebook专辑中获得超过100张照片

时间:2017-03-20 07:48:32

标签: php facebook-graph-api

我正在使用Facebbok Graph Api向我网站上facebook相册的照片展示。问题是它只显示了100张照片,但我的相册有超过100张照片。我尝试过这样的事情:

$album_image = $fb->get('/'.$album['id'].'/photos?fields=id,source,url&limit=500');   

$album_image = $fb->get('/'.$album['id'].'/photos?fields=id,source,url&limit=500');   

$album_images = $album_image->getDecodedBody();

1 个答案:

答案 0 :(得分:0)

<?php

require_once __DIR__ . '/Facebook/autoload.php';

$fb = new Facebook\Facebook([
  'app_id' => 'your app id',
  'app_secret' => 'your app secret',
  'default_graph_version' => 'v2.8',
]);

// Sets the default fallback access token so we don't have to pass it to each request
$fb->setDefaultAccessToken('app access token');

try {
  $response = $fb->get('/'your album id'/albums?fields=id,name,picture');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

$album = $response->getDecodedBody();
$album_ids = array();
$album_info = array();
$album_images_id = array();

foreach ($album['data'] as $key => $value) {
  $album_ids[] = $value['id'];
  $album_info[$value['id']] = $value;

  $album_image = $fb->get('/'.$value['id'].'/photos?tab=album&fields=id,source,picture');
  $album_images = $album_image->getDecodedBody();
  $feedEdge = $album_image->getGraphEdge();

    // Page 2 (next 5 results)
    $nextFeed = $fb->next($feedEdge);

    foreach ($nextFeed as $status) {
      var_dump($status->asArray());
    }
}

?>