Get all images from a specific Facebook album using the Graph API PHP SDK

Hi, I am trying to capture all the photos from a specific album (always the same hardcoded id). I am using the Graph API PHP SDK from Facebook. This is my code:

<?php require 'phpfiles/facebook.php'; $facebook = new Facebook(array( 'appId' => 'aaaa', 'secret' => 'bbbb', 'cookie' => true )); $user_profile = $facebook->api('/1881235503185/photos?access_token=cccc'); var_dump($user_profile); 

Result of var_dump:

 array(1) { ["data"]=> array(0) { } } 
  • 1881235503185 is the identifier of my album, which is not limited, it is open to everyone.
  • access_token is the token I get from my application page for my fb id. I'm not wrong.
  • I have permissions (user_photos) and you are trying to add a dozen other permissions.
  • When I try to use the Graph API, it works.

When I use the Javascript SDK, it works fine ...

 FB.api('/1881235503185/photos?access_token=cccc', function(response) { alert(response.data[0].name); }); 

Exit: Diep in the put

Did I forget something?

+8
php facebook facebook-graph-api
source share
3 answers

I understood! It should be:

 $user_profile = $facebook->api('/1881235503185/photos', array('access_token' => 'cccc')); 

Strike>

With the new PHP PHP SDK, it should be:

 $albumjson = $facebook->api('/1881235503185?fields=photos'); 
+7
source share
 <?php require_once 'library/facebook.php'; try{ $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $app_secret, 'cookie' => true )); if(is_null($facebook->getUser())) { header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}"); exit; } $me = $facebook->api('/me'); }catch(Exception $e){ echo $e->getMessage(); echo '<p>Please try clearing your browser cookies or <a href="http://demos.frnzzz.com/fbAlbum/photos.php">click here</a>.</p>'; die; } ?> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script> <script type="text/javascript" src="http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js"></script> <script type="text/javascript"> $(document).ready(function() { $('.slideshow').cycle({ fx: 'fade' }); }); </script> <title>WebSPeaks.in | Access facebook Albums on your site using PHP</title> </head> <body> <?php $albums = $facebook->api('/me/albums'); $action = $_REQUEST['action']; $album_id = ''; if(isset($action) && $action=='viewalbum'){ $album_id = $_REQUEST['album_id']; $photos = $facebook->api("/{$album_id}/photos"); ?> <div class="slideshow"> <?php foreach($photos['data'] as $photo) { echo "<img src='{$photo['source']}' />"; } ?> </div> <?php } $pageURL .= 'http://'.$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"]; echo '<div class="alb">'; if(strstr($pageURL,'.php?')){ $and = '&'; }else{ $and = '?'; } echo '<p class="hd">My Albums</p>'; foreach($albums['data'] as $album) { if($album_id == $album['id']){ $name = '<b><u>'.$album['name'].'</u></b>'; }else{ $name = $album['name']; } echo '<p>'."<a href=".$pageURL.$and."action=viewalbum&album_id=".$album['id'].">".$name.'</a></p>'; } echo '</div>'; ?> </body> </html> 
+3
source share

It seems strange to me that it works with JS and not with PHP ... It makes me think that this is related to your installation of PHP FB .. Have you tried another call to check this? For example,

 $facebook->api('/me'); 

Also make sure you check them:

To read the photo object you need

any valid access_token if it is public user_photos permission to access photos and albums uploaded by user user_photo_video_tags permission to access photos in which the user was tagged friends_photos permission to access photos of friends friends_photo_video_tags allows access to photos in which friends of friends are tagged

Src:

http://developers.facebook.com/docs/reference/api/photo/

+2
source share

All Articles