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

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.

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.

How to display all images uploaded with facebook post

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

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).

getting facebook comment by comment id

I am trying to get details of a comment by its comment id. This comments exists in a facebook comments box plugin which I have used in a website.
I tried the facebook api explorer and using this as the input
1388155601440738?fields=id,from,created_time
I got the response I wanted
{
"id": "1388155601440738",
"from": {
"name": "Ahmed Anas",
"id": "599062201"
},
"created_time": "2014-01-06T08:12:25+0000"
}
Unfortunately I cant figure out how to implement this in php..
I would assume all I need to do was get the contents from
http://graph.facebook.com/1388155601440738?fields=id,from,created_time
but I get an Unsupported get request exception
I also tried the php API with this code but no luck
$response = $facebook->api(1388155601440738);
$response = $facebook->api('/1388155601440738?fields=id,from,created_time');
I believe the comment id you are passing is incorrect. Also you have to add /comments after comment id. So the final URL for you would be something like http://graph.facebook.com/750281525001535/comments?fields=id,from,created_time. This one works fine

PHP activity feed - similar to Facebook - How to convert response from json to HTML elements

We are building a activity stream kind of website very similar to facebook (in activity feed alone). For loading user's activity feed, we send the request to PHP file through AJAX method. Server file will handle the logic and return back the values as an array in JSON format. I wanted to know, is there any framework available to write the JSON response to HTML elements. Also, the fees are not similar. It will vary according to the type (Photo, Album, Status Updated, Shared, Liked, etc). So i need to load different template view for each of the activity feed. Actions will be common like Share, Comments for all feeds.
Can you please share which will be the best approach to load the content according to the data received. Also the content need to be refreshed periodically. I have pasted the sample JSON response below for reference:
{
"id": "1",
"picture": "",
"link": "http://www.google.com",
"name": "Srini updated status",
"description": "Lorem ipsum",
"actions": [
{
"name": "Share",
"link": "http://networkedblogs.com/hGWk3?a=share"
}
],
"type": "statusupdate",
"created_time": "2011-05-10T18:35:38+0000",
"updated_time": "2012-07-20T10:42:58+0000",
"likes": {
"count": 0
},
"comments": {
"data": [
{
"id": "19292868552_10150189643478553_22286888",
"from": {
"name": "Lorenzo Portillo",
"id": "613727863"
},
"message": "does anyone knows why i get a rhombus and '?' in my app description when I publish in a user's wall, instead of a letter with accent?!?!?!?!?!?",
"created_time": "2012-05-28T13:48:45+0000"
},
"count": 1
}
}
Need help / suggestions on how to design the template according to the json array in javascript. Any comments / code help will be more helpful.
Thanks in Advance,
Regards
Srinivasan.C
Well, if you consider making a very robust app, take a good look at emberjs.
You should also try jquery's (jquery mobile, jquery ui, jquery ajax)
You can create an html output in your php file when you are getting the response from the Facebook API. According to me you can do json operation easily in PHP. By using json_decode you get array and that you can traverse it and build an html as per your requirement.
Hope it helps

Categories