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 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?