How to display all images uploaded with facebook post - php

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?

"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 :)

Related

get facebook post id from url link

I try to get a post id from an url in the graph explorer
for example I try to get the ID of this post in graph explorer
this is the url
http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112
And on Facebook this is the post
https://www.facebook.com/imdb/posts/10155250004608949
So the ID of the post is 10155250004608949
When I try to put my link on the graph explorer
It return me
{
"og_object": {
"id": "1460657060613493",
"description": "Untitled Jurassic World Sequel (2018)",
"title": "Latest Stills",
"type": "article",
"updated_time": "2017-03-08T22:45:48+0000"
},
"share": {
"comment_count": 0,
"share_count": 16
},
"id": "http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112"
}
I don't know what it is this id : 1460657060613493
So I don't know if it is possible to get the post id like that
I don't know what it is this id : 1460657060613493
That is the id of the Open Graph object that the URL http://www.imdb.com/gallery/rg1859820288/mediaviewer/rm1167930112 represents.
So I don't know if it is possible to get the post id like that
Of course it is not possible to get the post id via the IMDB URL, because “the” post id does simply not exist - multiple users and pages could have shared that IMDB URL.

Does Facebook Graph API Post Picture url (safe_image.php) expire?

I'm grabbing Facebook Post's pictures via Graph API call:
GET /mypageid/posts?fields=id,created_time,picture
Here's a sample response:
{
"data": [
{
"id": "1389378987988776_1745791089014229",
"created_time": "2016-08-03T21:55:39+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQBQL02u4kJtLNFs&w=130&h=130&url=fbstaging%3A%2F%2Fgraph.facebook.com%2Fstaging_resources%2FMDExNzQ1NzkwNjg5MDE0MjY5Ojk5ODEyOTY4Ng%3D%3D&cfs=1"
},
{
"id": "1389378987988776_1745301615729843",
"created_time": "2016-08-02T18:10:53+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQD7O17OAki29Gus&w=130&h=130&url=http%3A%2F%2Fcdn2.obsnocookie.com%2Fwp-content%2Fuploads%2F2015%2F03%2F13995025_770x433_acf_cropped.jpg&cfs=1"
}
}
Does the picture URL have an expiration date?
There is no specific expiration date afaik, but you should never rely on CDN links being available later according to Facebook. If you need them, you can download and store them on your own server.

Facebook api, some posts don't have an url to link to

I am getting some data in json format and putting it into a custom facebook feed on my website.
But I noticed some urls are not working, because it doesn't get a link to the post, while others do have a link.
What is the reason for that?
Example (I edited the real data):
{
"full_picture": "facebook.com/image.jpg",
"story": "Lorem ipsum added 5 new photos.",
"link": "facebook.com/loremipsum",
"updated_time": "2016-04-21T08:11:56+0000",
"id": "267007566742236_9112352353963611923"
},
{
"message": "lorem ipsum",
"updated_time": "2016-05-26T18:58:50+0000",
"id": "267007566742236_90323523789831074"
},
Like you can see, one has a link, but the other doesn't. If I go to the facebook page and click on the date of the post, it opens in a new tab, so there should be an accesible url.
I get everything with file_get_contents:
$json_object = file_get_contents("https://graph.facebook.com/v2.6/267032532566742236/feed?fields=full_picture%2Cmessage%2Cstory%2Clink%2Cupdated_time&access_token=23532523523523%dsgsdg322352352235");
The link property of post objects is for the URL that might have been attached to the post.
What you want, is the permalink_url field.

Can i use the facebook api to get details about who posted on my facebook page?

As the title mentions, i wish to make a feed on a website, with the message a user posted on my facebook page and also his name and profile picture.
I managed to get the messages from my fb page but that's about all
{
"data": [
{
"message": "message",
"created_time": "time",
"id": "id"
},
{
"message": "message",
"created_time": "time",
"id": "id"
}
]
}
I have been struggling with this for some time now, is it even possible ?
You should declare the fields you want (see the doc), in your case, the from field (see post node reference).

How to get user's network information using Facebook Graph API? (PHP)

I have been playing with Facebook Graph API around a week, and I still could not find how to get user's network information? I don't know if the Graph API stores user's network; I didn't see such information. Simply, if a user is in "Google" network, may I get the name and the ID of the networks that the user belongs to?
If this is not possible, may I reach the user's secondary email addresses?
Thanks for your help.
Using FQL : the affiliations field of the User table contains this information
Sample call:
https://graph.facebook.com/fql?q=select affiliations from user where uid= 4&access_token=<ACCESS TOKEN>
Sample response:
{
"data": [
{
"affiliations": [
{
"nid": 16777217,
"name": "Harvard",
"type": "college"
},
{
"nid": 50431648,
"name": "Facebook",
"type": "work"
}
]
}
]
}

Categories