display photos from facebook with javascript api?

六眼飞鱼酱① 提交于 2019-12-03 08:53:09
Juicy Scripter

This can be done by issuing Graph API request to photos connection of album:

FB.api('/me/albums?fields=id,name', function(response) {
  for (var i=0; i<response.data.length; i++) {
    var album = response.data[i];
    if (album.name == 'Profile Pictures'){

      FB.api('/'+album.id+'/photos', function(photos){
        if (photos && photos.data && photos.data.length){
          for (var j=0; j<photos.data.length; j++){
            var photo = photos.data[j];
            // photo.picture contain the link to picture
            var image = document.createElement('img');
            image.src = photo.picture;
            document.body.appendChild(image);
          }
        }
      });

      break;
    }
  }
});

You use the graph to do it... all you need is the album.id from above, and then you make a call to the graph to get the photos. I passed fields=pictures to tell facebook to only return the picture links. You can omit this parameter and it will bring you a whole bunch of stuff back.

https://graph.facebook.com/<album.id>/photos?fields=picture

The list of all of the fields can be found here Album - Graph API

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