How to get the total number of posts on a Facebook page using the Graph API?

I use the Facebook API to crawl information from a public page. The current problem is how to get the total number of posts on a Facebook page. If we go to / {page-id} / posts, it will only return 25 posts posted on this page, and no summary information mentions the page margins. I checked the previous answer, it seems that the only way is to count the number of elements of each link in the next and get the total number. But it is very inefficient. Is there any method that can directly get a shared entry on a page other than FQL?

+5
source share
3 answers

Facebook does not actively count the number of posts made by the page; depending on the page, this may be an astronomical number.

You will need to receive all messages and calculate them yourself. I would use something like this.

{PAGE}/posts?fields=id&limit=250 

It will return the smallest possible data set that you need. You cannot go above 250, you can with FQL, but not with v2.1. Also, you do not want FEED, because it is an aggregation of pages and messages made on the page by other users. This will return such an object.

 { "data" : [ PostData ... ], "paging" : { ... "next" : CursorURL } } 

This is the cursor URL, so you can disable groups of 250 messages in reverse chronological order.

You can reduce the score by increasing 250 each time you get a new cursor that also returns more messages. You will only need to count and add the results to the set using the second to the last cursor, since the last cursor will return an empty data array.

+1
source
  function p_post() { FB.api("/209652442394600/posts?fields=admin_creator,name&limit=250", function (response) { var t = response.data.length; document.getElementById('tposts').innerHTML = t; }); } 

It works up to 250, and I used it last week.

+2
source

You can try adding /page/posts?limit=1000 , but I'm not sure if this will work. You can also try using /page/feed to see if it will get the desired results. If none of these things work, then most likely you will not be able to receive the total number of messages. In addition, FQL will be deprecated next year.

0
source

Source: https://habr.com/ru/post/1205487/


All Articles