douzhan8303 2011-08-10 04:38
浏览 67
已采纳

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

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.

  • 写回答

3条回答 默认 最新

  • duanmu6231 2011-10-14 21:25
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据