How to display all images uploaded with facebook post

时间:2016-10-20 12:39:22

标签: php facebook-graph-api facebook-javascript-sdk facebook-php-sdk

I'm using facebook SDK for PHP to get post on user timeline. I use api "/me/feed" to get the timeline. The problem is that I can display text only. I want to display all image which uploaded or shared by each post. How can I do that?

1 个答案:

答案 0 :(得分:0)

"me?fields=posts{type}" - Gives you all posts of authorized user. From that result, you'll get type attribute mentions Link, Photo, and Video. So you can filter photo only to show all user photos.

"me?fields=photos" - Gives you all photos of user's tagged(Uploaded by user friends).

"me?fields=posts{picture}" Gives you only posts with Photos.(Which you need). The return JSON format is followed.

{
  "posts": {
    "data": [
      {
        "picture": "https://fbcdn-photos-d-a.akamaihd.net/hphotos-ak-xtp1/v/t1.0-0/s130x130/14718778_1841680516118589_7768474098175322373_n.jpg?oh=6e53b43361b48c3568a72dd5b651d312&oe=588D34A5&__gda__=1486132096_8b0bef43cf74166a9b88391a7bcb9195",
        "id": "319551818195811_717085918443189"
      },
      {
        "picture": "https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-xal1/v/t1.0-0/s130x130/14724654_1745688559098754_6408885771776123938_n.png?oh=9fbab8e118743gbaf2854e60945e5dec&oe=58ABE2A0&__gda__=1486058914_4df4fb64e7b307205bbc3db4fccfc3fa",
        "id": "319551818195811_717085918443189"
      },
      {
        "picture": "https://fbcdn-photos-c-a.akamaihd.net/hphotos-ak-xal1/v/t1.0-0/s130o130/14724654_1745633559098754_6435045951276123938_n.png?oh=9fbab8e118746bbaf2854e60945e5dec&oe=58ABE2A0&__gda__=1486058914_4df4fb64e7b307205bbc3db4fccfc3fa",
        "id": "319551818195811_717085918443189"
      }
      }
    ]
}

From that JSON, "Picture" is Photo URL which you posted to FB. You can embed to an image tag to show it on your website.

Note : JSON is Modified

Hope This helps :)