PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 3, 2022

[FIXED] How to get the total number of posts in a Facebook page with Graph API?

 November 03, 2022     facebook, facebook-graph-api     No comments   

Issue

I am using Facebook Graph API to crawl information from 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 mentioned the page's fields. I have check the previous answer, it seems that the only way is to count the number of items of each link in next and get total number. But it is very inefficient. Is there any method that can directly get the total post on a page other than FQL?


Solution

Facebook doesn't actively count the number of posts a page has made; depending on the page it could be an astronomical number.

You would have to get all the posts and count through them yourself. I would use something like this.

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

It will return the smallest possible data set you need. You can't go above 250, you could with FQL but not with v2.1. Also you don't want FEED because that is an aggregation of the Page's Posts and the Posts made to the page by other users. This will return an object like this.

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

This is the cursor URL so you can step down the groups of 250 posts in reverse chronological order.

You can shortcut the counting by incrementing 250 every time you get a new cursor that also returns more posts. You will only have to count and add the results in the set with the 2nd to last cursor since the last cursor will return an empty data array.



Answered By - Frank D
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing