获取我管理的群组中的所有相册

I've manage a martial arts school's website, the schook also has a facebook group where friends and students can publish their news and photos.

I would like to fetch the group's albums and display their pictures in the website of the school.

So I tried this short script:

<?php
require_once(__DIR__.'/lib/facebook.php');
$facebook = new Facebook(array(
  'appId'  => 'API_KEY',
  'secret' => 'API_SECRET',
));

$group = $facebook->api('GROUP_ID');
echo $group
?>

Which is raising this error in the app's log

Wed Aug 10 01:16:30 2011] [error] [client 127.0.0.1] PHP Fatal error: Uncaught CurlException: 6: name lookup timed out thrown in './lib/base_facebook.php on line 814

So I wonder if this is the way to do it or if I should try getting the albums from elsewhere...

I find the documentation in developers.facebook.com scarce or confusing.

This is how I get my albums, I think the group album must be similar.

  1. create a Facebook application. If you don’t already have one usable for this project create it on http://developers.facebook.com/setup/. You will own App Name, App URL, App ID, and App Secret get access code, go to:

    https://www.facebook.com/dialog/oauth?client_id=Your_App_ID&redirect_uri=Your_App_URL&scope=read_stream,publish_stream,offline_access

    You must allow the application to gain access to your account. (allow access to pictures to) After you click allow, your browser will be redirect to Your_App_URL with additional URL attribute, it will look something like:

    Your_App_URL?code=long_facebook_code

  2. get offline access token, go to

    https://graph.facebook.com/oauth/access_token?client_id=Your_App_ID&redirect_uri=Your_App_URL&client_secret=Your_App_Secret&code=long_facebook_code

    the page will display something like

    access_token=123456789|99bdea74e40ecc75530b7c45-132456798|dTntC8lVyR84eBxK1TS9ws2s_s0

    Note: make sure there are no word “expire=” in the end of the token (the bold text) copy your offline token (only the bold text) and use it, it permanent token and never change event if you change your application name.

  3. then I use a script in PHP (PHP SDK 3.0.):

  require 'src/facebook.php';
  $appId = 'Your_App_ID';
  $secret = 'Your_App_Secret';
  $access_token = 'Your_access_token';
  $facebook = new Facebook(array('appId' => $appId, 'secret' => $secret, ));
  $facebook->setAccessToken($access_token);

to see available albums:

// bring the id, name and number of pictures.
$albums = $facebook->api('/me/albums?fields=name,count'); 
print_r ($albums);

to read the album:

$album_ID = "123456..."; //album ID
$list_pictures = $facebook->api('/'.$album_ID.'/photos', array('access_token' => $access_token));
print_r ($list_pictures);

You can not use /photos and /albums for group by Graph API. First always return empty data, second - error "(#3) App must be on whitelist"

I created a python project to resolve this problem for a friend. You can't access the albums without being a trusted Facebook app, but you can access the feed, which contained the bulk of the images I wanted to grab.

This will download and archive everything (which is what they wanted) but I thought it might help you as well.

https://github.com/danfunk/ethans_fight