Requesting Posts and Photos in a single request - facebook-graph-api

I'd like to know if there's a way to request a page's feed and also the pictures in each post. Getting each one separately isn't hard:
PAGE_ID?fields=id,name,cover,fan_count,posts
POST_ID?fields=full_picture
I've tried using batch. I wasn't able to get both in one request, I ended up with only the photos but not the posts (data) associated with.

Found a way to do it, thanks to https://stackoverflow.com/a/27524411/2124535
Graph API request:
PAGE_ID/posts?fields=picture,full_picture,attachments,description,message
or even simpler:
PAGE_ID/posts?fields=full_picture,message

Related

Can we get who all liked our page post in Facebook using their APIs?

I tried to consume Facebook API which need to get the list of who liked my post in my page. Is there any endpoint available in v15.0 (latest) ?
For Example:
If I have a page named "Restaurant" and i have posted a story on that page's feed as "New restaurant on the way to launch" and peoples are liking that post. I want to retrieve who and all liked that post along with the total count. How is it possible ?
Also a question, if a private account is liking that post in that "Restaurant page", how will it be counted too and can we fetch those details too ?
I have tried with the URL, https://graph.facebook.com/101882636084088/feed to get the page feeds and https://graph.facebook.com/{page-id}_{post-id}/likes, but I'm not able to fetch likes.
I also tried, https://graph.facebook.com/{page-id}_{post-id}?fields=likes.summary(true), I'm not getting proper count or who and all liked as response. Have anyone came across this scenario ?

How to add attachments to a post Facebook API

When I look at the JSON data of a post which has several photos, I see that, this is done by using attachments/subattachments.
I want to post a data with several pictures and to do this, I want to take the advantage of attachments.
When I use "object_attachment" field for the post (to page feed), it creates only one attachment. Adding several "object_attachment" fields have no effect, only the first photo is used.
I want help on how to create attachment for a post and then add this attachment to the post.
Facebook says, attachments may be added to the posts to the post by "attachment_id" field.
Thanks to eveone who helps.

Facebook Graph API collect posts only recently updated

I am currently collecting all page posts via the api using the since parameter i.e.
12345678910/feed?since=[LastCheckTimeUnix]
However I need to know if any earlier posts have been updated, using the updated_time field.
The only way I can see is to collect every post ever posted and then check the updated_time. However this is obviously inefficient. Is there a way to obtain all posts with an updated_time > LastCheckTime?

Facebook API: How to get all data related to a post?

I'm trying to get all data related to a particular post like comments, likes, view count, etc in one API call. I can get likes by {post-id}/likes and comments by /{post-id}/comments.
How do I get all this detail in one API call?
Try
/{post_id}?fields=id,message,likes,comments
See
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.4#fields

using POST request on Facebook Graph API

I want to access graph API to get the number of shares for different pages of my website. I can use the GET method to do so but I want to use POST so that I can send more url in a single request. The current implementation I have for GET is
http://graph.facebook.com/?ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/
Can anyone please help ?
This is badly documented (I mean I didn't find the information when I looked for it!), but there is way to pass all the parameters to the Graph API through POST method:
in your example, you should POST to http://graph.facebook.com/
with the following DATA:
ids=http://umairj.com/,http://umairj.com/146/how-to-clear-facebook-shares-cache/&method=GET
I'm not sure about the encoding of the POST DATA..in our case, we were just using ids=.....,.....,..... with numeric FB user ids and we didn't need to do any encoding, but you might need some url-encoding
Don't forget the &method=GET or it won't work ! It helped me break the url length limit that was causing bugs on Internet Explorer (I think RFC says 1024 characters, all browsers support much more, IE only ~4096 ) when we were passing too many ids through GET
if you wish to access non-public information, the same trick works with https://graph.facebook.com/ , provided you add &session_token=***** to your query
You can try to run a FQL query to get the stats for multiple urls. Facebook link_stat documentation has an example of how to do this. I'm pretty sure you can't POST to either the FQL query or the graph api you were using though unfortunately. Your FQL query would be:
SELECT url, share_count, like_count FROM link_stat WHERE url IN("http://umairj.com/","http://umairj.com/146/how-to-clear-facebook-shares-cache/")
Here is the url after properly url encoding the query: https://api.facebook.com/method/fql.query?query=SELECT+url%2C+share_count%2C+like_count+FROM+link_stat+WHERE+url+IN%28"http%3A%2F%2Fumairj.com%2F"%2C"http%3A%2F%2Fumairj.com%2F146%2Fhow-to-clear-facebook-shares-cache%2F"%29&format=json
Facebook provides a FQL testing tool to help.
Update: their API documention (see section titled "Delete) mentions you can do an HTTP POST to any of their methods and set the variable method to the method you want. You could try this, although this was designed for delete and put methods not available to javascript clients. It still looks like is all url based so I'm not sure it will take a form encoded parameter like you are looking to do.
I work at Facebook and I've updated our Graph API documentation to document this work around for very large requests:
https://developers.facebook.com/docs/graph-api/using-graph-api#largerequests