vbjain
vbjain

Reputation: 557

Get "Post Count" from public page using Facebook Graph API

I want to get a number of posts from a page in last month. Is is possible with facebook graph API? Also FYI, i just have the access_token to interact with the Facebook API.

Also do anyone knows how to fetch the number of Page mentions in last month?

Thanks for your help in advance.

Upvotes: 3

Views: 16386

Answers (1)

Hari Krishna Ganji
Hari Krishna Ganji

Reputation: 1677

Try using Facebook's Page Insights using Facebook Graph API's :

https://developers.facebook.com/docs/graph-api/reference/insights/#page_posts

But please note that you need to be a page admin for this page, and you need to acquire a Page Access Token with the permissions 'read_insights'.

If you are not a page admin, then you can also do the same with an User Access Token or an App Access Token.

Steps:

  1. `int postsCount = 0;
  2. Use the following API query https://graph.facebook.com/{page-id}/posts and issue a reuquest.
  3. Count the posts fetched. postsCount = postsCount + {the posts json array size}.
  4. Store the cursor returned by the above API result. Use it to fetch the next page of Posts.
  5. If the {the posts json array size} > 0, then goto step 3.

Notes:

  • I am sure that you can do it better with FQL, but I am guessing FQL is being deprecated.
  • I think there is a summary(true) annotation (https://graph.facebook.com/{page-id}?fields=posts.summary(true)) that you can use, but I couldn't get it working.
  • There is an API rate limit that you need to keep in mind. And do some throttling.

So, the moral of the story is that I am not sure if Facebook really wants you to crawl its Pages if you are not the Admin of the page. :-)

Upvotes: 8

Related Questions