Displaying images from Facebook photo albums on a portfolio site using the graph api

我与影子孤独终老i 提交于 2019-12-03 14:06:59

问题


A client of mine would like to be able to update her site's image galleries by adding images to albums on her facebook account. Is this possible using JSON? would the albums she chose to display need to be made public? Thanks for any help on this!


回答1:


This is definitely possible by using the graph api:

Get the ID of all of her albums - select the one you want:

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

Access the album:

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

You need the user_photos permission and the album needs to be public.

This returns you a list of all the photos in the following JSON form:

{
          "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"
              }
}

You can then use the source of the photo to get the full sized image




回答2:


https://graph.facebook.com/USER_ID/albums/ would get you 25 most recent albums and you must set the 'limit=0' in the url like

https://graph.facebook.com/USER_ID/albums/?limit=0 this would get u all the albums... and also make sure your album 'Wall Photos' is set to public otherwise you'll require 'user_photos' permission.

then you need to get the album id of the album with title 'Wall Photos' and you can retrieve the photos using that album 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;
    }
}

you can then use the album '$wall_album_id' to get the wall photos...



来源:https://stackoverflow.com/questions/3732685/displaying-images-from-facebook-photo-albums-on-a-portfolio-site-using-the-graph

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!