title: Facebook API for PHP: how to get user albums and photos?
body: <p>Hello I'm using Facebook API for PHP (latest version) and I'm trying to get all albums with photos of an user.</p>
  
  <p>I wrote this code:</p>
  
  <pre><code>&lt;?php
  require_once "common.php";
  
  if( !isset( $_SESSION['facebook_access_token'] ) ){
      header("Location: index.php");
      exit;
  }
  
  $token= $_SESSION['facebook_access_token'];
  
  try {
      // Returns a `Facebook\FacebookResponse` object
      $response= $fb-&gt;get('/me?fields=id,name,first_name,last_name,gender,link,birthday,location,picture', $token);
  } catch(Facebook\Exceptions\FacebookResponseException $e) {
      echo 'Graph returned an error: ' . $e-&gt;getMessage();
      exit;
  } catch(Facebook\Exceptions\FacebookSDKException $e) {
      echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
      exit;
  }
  
  $user= $response-&gt;getGraphUser();
  
  $albums = $fb-&gt;get('/me/albums', $token);
  
  $action = ( isset($_REQUEST['action']) ) ? $_REQUEST['action'] : null;
  
  $album_id = '';
  if($action=='viewalbum'){
      $album_id = $_REQUEST['album_id'];
      $photos = $fb-&gt;get("/{$album_id}/photos", $token);
      ?&gt;
      &lt;div class="slideshow"&gt;
          &lt;?php
          foreach($photos['data'] as $photo)
          {
              echo "&lt;img src='{$photo['source']}' /&gt;";
          }
          ?&gt;
      &lt;/div&gt;
  &lt;?php
  }
  
  $pageURL = 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  echo '&lt;div class="alb"&gt;';
  if(strstr($pageURL,'.php?')){
      $and = '&amp;';
  }else{
      $and = '?';
  }
  
  echo '&lt;p class="hd"&gt;My Albums&lt;/p&gt;';
  foreach($albums['data'] as $album)
  {
      if($album_id == $album['id']){
          $name = '&lt;b&gt;&lt;u&gt;'.$album['name'].'&lt;/u&gt;&lt;/b&gt;';
      }else{
          $name = $album['name'];
      }
      echo '&lt;p&gt;'."&lt;a href=".$pageURL.$and."action=viewalbum&amp;album_id=".$album['id']."&gt;".$name.'&lt;/a&gt;&lt;/p&gt;';
  }
  echo '&lt;/div&gt;';
  </code></pre>
  
  <p>I've found this example here: <a href="https://stackoverflow.com/questions/6678756/get-all-images-from-specific-facebook-album-with-graph-api-php-sdk">Get all images from specific Facebook album with Graph API PHP SDK</a>
  But is says: Cannot use object of type Facebook\FacebookResponse as array on line 53 (I've changed but don't work at all because API function doesn't exist!)</p>
  
  <p>I've also tried to follow the documentation: <a href="https://developers.facebook.com/docs/graph-api/reference/user/photos/" rel="nofollow noreferrer">https://developers.facebook.com/docs/graph-api/reference/user/photos/</a></p>
  
  <p>But execute function doesn't exist! What shall I do?</p>