How to get images from facebook album using facebook api

Published on : August 12, 2014

Author:

Category: Facebook Fanpage and App


You  can get images from Facebook album using Facebook api. Follow the steps below and you can do it easily

Step 1: Download facebook php sdk from the given link

https://github.com/facebook/facebook-php-sdk

Step 2: Go to facebook developer page and open a facebook app

https://developers.facebook.com/apps/

Step 3: create your index.php file to get facebook album and facebook image source.

Sample Code: index.php

[sourcecode]</pre>
<?php

require ‘facebook-php-sdk-master/src/facebook.php’;

$appId = ‘Your facebook App ID/API Key’;

$secret = ‘App secret’;

$access_token = ‘Access Token’;

$facebook = new Facebook(array(‘appId’ => $appId, ‘secret’ => $secret, ));

$facebook->setAccessToken($access_token);

$albums = $facebook->api(‘/me/albums?fields=id’);

foreach($albums[‘data’] as $row){

$list_pictures = $facebook->api(‘/’.$row[‘id’].’/photos’, array(‘access_token’ => $access_token));

foreach($list_pictures[‘data’] as $row1){

echo $row1[‘source’].'<br>’;

}

}

?>
<pre>[/sourcecode]

Sample output


Leave a Reply

Your email address will not be published. Required fields are marked *