Retrieve photo albums from Facebook using Graph API

My head is currently going nuts trying to figure out the most effective way to retrieve the albums from a fan page I own, to an online page. I’ve seen a code that used FQL and it worked, but it’s too slow and apparently it’s outdated.

I’ve browsed around and came across the Graph API concept but it looks a bit hard to understand. By the way I already have an app registered and I also started to search around the Graph Explorer but I can’t come to a conclusion.

Read More

Are there any tutorials out there?

EDIT: I’ve tried this code:

<?php
$album_id = 'myalbumid';
$access_token = 'accesstoken';

$url = "https://graph.facebook.com/{$album_id}/photos?access_token={$access_token}";
$image = json_decode(file_get_contents($url));

foreach($image->data as $img){
echo "<img src='{$img->images[6]->source}' />    ";

}
?>

And it works, it displays all the photos from a given album. But what if I want it to display all albums (including thumbs) and the user navigates through them?

Related posts

Leave a Reply

1 comment

  1. Requesting the following will give you a reply with all albums and photos in those albums:

    https://graph.facebook.com/CocaCola/albums?fields=photos
    

    You’ll want to replace CocaCola in the example with your own page name or ID.

    This is called nested requests or field expansion. There are several detailed examples on the Facebook Documentation site.

    A few comments for you to help you along the way:

    • Calls to retrieve page objects don’t need an access token so long as the page does not have age and/or country restrictions. Unless you legally need them, I wouldn’t recommend adding restrictions.
    • Using file_get_contents() is okay for sandbox testing, but you should use the Facebook PHP SDK for production code.