【问题标题】:Displaying images from Facebook photo albums on a portfolio site using the graph api使用图形 api 在投资组合网站上显示来自 Facebook 相册的图像
【发布时间】:2010-09-17 04:35:37
【问题描述】:

我的一位客户希望能够通过将图片添加到她的 Facebook 帐户上的相册来更新她网站的图片库。这可以使用 JSON 吗?她选择展示的专辑需要公开吗?感谢您对此的任何帮助!

【问题讨论】:

    标签: json facebook image-gallery facebook-graph-api


    【解决方案1】:

    这完全可以通过使用graph api来实现:

    获取她所有专辑的 ID - 选择您想要的:

    https://graph.facebook.com/me/albums/

    访问相册:

    https://graph.facebook.com/ALBUM_ID/photos

    您需要 user_photos 权限,并且相册需要公开。

    这会以以下 JSON 格式返回所有照片的列表:

    {
              "id": "104988432890979",
                     "from": {
                        "name": "Patrick Snape",
                        "id": "100001394674670"
                     },
                     "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc4/hs272.snc4/39934_104988432890979_100001394674670_46790_6171664_s.jpg",
                     "source": "http://sphotos.ak.fbcdn.net/hphotos-ak-snc4/hs272.snc4/39934_104988432890979_100001394674670_46790_6171664_n.jpg",
                     "height": 540,
                     "width": 720,
                     "link": "http://www.facebook.com/photo.php?pid=46790&id=100001394674670",
                     "icon": "http://static.ak.fbcdn.net/rsrc.php/z2E5Y/hash/8as8iqdm.gif",
                     "created_time": "2010-08-11T10:32:45+0000",
                     "updated_time": "2010-08-11T10:32:47+0000"
                  }
    }
    

    然后您可以使用照片的来源来获取完整尺寸的图像

    【讨论】:

    • /albums URL 似乎没有列出“Wall Photos”相册 ID。有谁知道为什么?还有其他方法可以获取墙上的照片吗?
    【解决方案2】:

    https://graph.facebook.com/USER_ID/albums/ 将为您提供 25 张最近的专辑,您必须在 url 中设置“limit=0” 喜欢

    https://graph.facebook.com/USER_ID/albums/?limit=0 这会得到你所有的专辑... 并确保您的相册“Wall Photos”设置为公开,否则您将需要“user_photos”权限。

    那么您需要获取标题为“Wall Photos”的专辑的专辑 ID 您可以使用该相册 ID 检索照片

    $wall_album_id='';
    $url = "http://graph.facebook.com/me/albums?fields=id,name&limit=0";
    $obj = json_decode(file_get_contents($url));
    foreach($obj->data as $item) {
        if ($item->name == 'Wall Photos'){
                $wall_album_id=$item->id;
                break;
        }
    }
    

    然后您可以使用相册“$wall_album_id”来获取墙上的照片...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 2013-03-11
      • 2021-12-08
      • 2017-08-27
      相关资源
      最近更新 更多