Facebook post id returned using graph api and the posted Id on facebook are not same - facebook

I need to retrive the comments for the particular post on Facebook, so whenever i post sometext on facebook using graph api as mentioned below.
$result = $facebook->api($fid.'/feed/','post',$attachment);
It returns the post id in response($result).
When i login to facebook and hover on the "datetime" for that post, it shows me the different post id and not the returned one in my response, so i couldn't get the comments for that post id.
I use to get the comments using the code below.
$post_comments = $facebook->api('/'.$postid,array('access_token' =>'AAAAxxxxxx'));
Any Help would be Appreciated!
Thanks,

The Post ID returned by the API is in the form {user_id}_{post_id} so its slightly different than the one facebook shows. However, if you replace the _ with /posts/ you get the same URL as the one Facebook provides.

I ran into this behaviour myself some days ago – user used three different apps and thereby created three individual link-posts. The "x minutes ago"-link for each of them showed a different number of minutes, but clicking on any of them led to the same post, the first on that was made.
I suspect it has something to do with all three post being made from page tabs on the same fan page(?) – but i looks like a bug to me, because to any of his friends following the "x minutes ago"-link on one of the other two posts it surely must be a bit confusing to be taken to a different post detail page than the one the actually clicked on.

Related

FB graph API get post comments by given user

Do you know if its possible to get the list of post comments by given user?
I tried this: <post_id>/comments?fields=from.id(<user_id>) but it still returns array of all post comments. I think I have enabled all the permissions because I can see the from field but it looks like 1) the filter is not working, 2) I am doing it wrong. The graph API version I am using is v9.0
My goal is to get list of comments by given user or receive an empty array if the user didnt comment the post. Maybe there is a different way how to do it..
You cannot do this by calling the graph api anymore :/
But, there is some kind of workaround you may be able to do.
First, you'll have to set a page webhook to retrieve all the comments written on your page. Find the documentation here: https://developers.facebook.com/docs/pages/realtime
The information sent to your server via the new comment's webhook contains the "from" data, looking like this:
{
name: "Foo Bar", // the user's name
id: "12345" // A user ID (unique for your page. Will be different for the same user accross 2 different pages)
}
You may then be able to pick only the wanted user's comment
I clearly see 3 downsides to this workaround:
It only works with pages
You need to handle in realtime all the comments written on your page
You cannot retrieve the comments posted in the past

How to post a status message to facebook with TO target using facebook4j?

I am using facebook4j to add fb page feed posting capabilities to an existing system. Initially I thought it would just be for posting to pages, which is done, but many pages don't allow posting. In such a case I need to fall back to targeting the individual in a status message. In facebook such a post shows up with heading like "{User's Name}‎ > {Target's Name}".
The problem I'm running into is that even though the facebook graph api has a "to" attribute for a message, I can not find a way to accomplish this with facebook4j. The postStatusMessage() method appears to only accept the id of the feed to post to and the PostUpdate class does not have a "to" property. I could of course be misunderstanding what the arguments represent or how this should be accomplished.
Any suggestions would be appreciated.

Get Share Count of Public Video with FB API v2.5

The Short Version:
"I can visit the public page without being logged into Facebook and see underneath the post is says "2155 shares" I would like to know how to access that number through the API"
The Details:
I'm trying to use the newest version (v2.5) of the graph HTTP API to determine the total share count for a public video. The problem is FB seems to have changed the API enough that older posts on SO no longer answer this question.
Looking at the Graph API Documentation it appears that video nodes now have the "sharedposts" edge. However, calling this route with summary=true only returns a few of the shares and no value for a total count. This returns counts for comments and likes so I'm not using the endpoints incorrectly or messing up my authorization.
I've also tried to use the URL Node but this doesn't seem to do much with links inside of Facebook. I simply get a JSON response with an 'id' field with the same url I supplied as a request parameter. Seems like this route is meant to be used for links to content outside of Facebook.
I've tried the above methods with multiple videos on multiple public pages so I don't think it is due to the group owners restricting access, unless this is the new default.
It seems arbitrary that I would be allowed access to total counts for comments and likes, but not shares. Is there some legacy way to do this or am I out of luck for now?
You should query the Post element containing the Video element.
Each video posted is also contained in a post element.
The post id is then composed of the video id prepended with the posting entities id (user, page etc'), separated with an underscore.
It then looks like: user-id_video-id.
Then using the Graph API to get the share count of a post is straightforward:
GET /v2.5/{post-id}?fields=shares
Example
Lets take a video from the BBC page:
https://www.facebook.com/bbcnews/videos/10153524838517217/
(Please tell me if the link is broken. I'll switch it to something newer :))
Video id : 10153524838517217
Page id (see below): 228735667216
--> Post id: 228735667216_10153524838517217
And the request would be:
GET /v2.5/228735667216_10153524838517217?fields=shares
(open in the Graph API explorer)
Page id
to get the page id, you could query the video element for the from field.
GET /v2.5/10153524838517217?fields=from

Facebook Insights - Post Details

In the "Posts" section of Facebook Insights, you can click on your latest posts and get detailed information about them:
I'm trying to recreate this data in a web application, using the Facebook SDK for .NET. I have found most of these numbers through Facebook's Graph API, e.g:
.../v2.3/(page-id_post-id)/insights/post_impressions_unique/lifetime
.../v2.3/(page-id_post-id)/insights/post_stories_by_action_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_consumptions_by_type/lifetime
.../v2.3/(page-id_post-id)/insights/post_negative_feedback_by_type/lifetime
...except the post content and the numbers marked in red. Using Fiddler, it looks like Facebook fetches these values from a URL outside the Graph API:
https://www.facebook.com/ajax/pages/insights/view_story/...
However, that URL is only accessible if you're logged in to Facebook. So, the question is:
Given an access token, can my (server-side) web application somehow get the post content, or at least the missing numbers? Preferably using the Facebook SDK, but any solution will do.
Update:
As #CBroe points out, simply querying the post id itself gives you enough info to recreate the post content:
.../v2.3/(post-id)?fields=name,message,picture,link
So, the last piece of the puzzle is to get the missing numbers. "Likes - On Post" can be found by querying the post's /likes with a summary:
.../v2.3/(page-id_post-id)/likes?limit=0&summary=true
..but "Comments - On Post" and "Shares - On Post" are trickier.
Querying .../v2.3/(page-id_post-id)/comments does give the number of comments on the post, but doesn't include answers to those comments, which are included in the number 5 in the picture above. You can recursively query /comments on each comment id, but that would generate too many queries to be worth it.
One might think that querying .../v2.3/(post-id)/sharedposts could give you the number of times a post has been shared, but it only gives you a few of the shared instances (due to other users' privacy settings?)
to clarify, you're trying to get the number of likes, comments, and shares.
Likes [post_id]/likes?summary=True&limit=0
NOTE: You can also call it when calling the post fields [post_id]?fields=id,likes.summary(true).limit(0)
Comments [post_id]/comments?summary=true&limit=0
NOTE: comments edge has a param filter https://developers.facebook.com/docs/graph-api/reference/v2.3/object/comments which may be why you see different numbers
NOTE: You can also call then when calling the post fields [post_id]?fields=id,comments.summary(true).limit(0)
Shares [post_id]?fields=shares
the sharedposts edge is empty b/c you don't have "read_stream" permission for the user's posts, https://developers.facebook.com/docs/graph-api/reference/v2.3/object/sharedposts#readperms
Edit (by OP):
Adjustments to get the same numbers that are presented in the "Post Details" popup:
Comments - On Post: (page-id_post-id)/comments?filter=stream&summary=true&limit=0
Using only post-id without prepending page-id gives the same result, but you also get a debug message saying "...actual number of results returned might be different depending on privacy settings."
Shares - On Post: (post-id)/sharedposts?fields=id
Don't prepend page-id here - that yields an empty result set.
Sadly, ?summary=true doesn't work, so I used the fields filter just to reduce the amount of data.
The suggested (post-id)?fields=shares gives a different number which seems similar to the insights numbers, but doesn't add up to any of them.

FB graph API problems with reading posts (type=status)

I'm trying to analize a large number of posts from varoius pages for my bachelor thesis. Therefore I'm using a tool called Facepager which uses the graph API to fetch data from Facebook.
I need the following data:
id, link, type, from and the count of likes, shares and comments (just the numbers, no further info!). In general, everything is working just fine, only posts classified type=status behave strangely. For some of these posts, there is no data shown about like, share and comment counts, further more there is no link given. But as mentioned before, this only happens sometimes! I searched for the affected posts manually on facebook and some of them had a large number of likes, shares or comments.
I also tried to fetch data with graph API explorer with similar results.
Is there any reason why it isn't possible to get share, like and comment count on some of the posts classified type=status?
Additionally, I'm planning to use the ID or if invalid, the link to open specific posts in my browser. This is not possible for some of the status posts either.
Sorry for that newbie question, it would be amazing if I could get an answer because at the moment I am quite desperate because this is really important for my bachelor thesis. Thanks a lot!
Because this kind of post is a post which "CAN NOT BE VIEWED".
ex: "xxxx likes a link", or "XXX commented on a post".
I suggest that you should filter out these posts by yourself.