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

You can only retrieve a summary/count for published posts on a page. Something like this will work when querying the Page directly:

{PAGE}?fields=published_posts.limit(1).summary(total_count).since(1)

The response will look something like:

{
    published_posts: {
        summary: {
            total_count: 12345
        },
        ...
    }
}

or if you want to query the published_posts directly, use:

{PAGE}/published_posts?limit=1&summary=total_count&since=1

The response will look something like:

{
    summary: {
        total_count: 12345
    },
    ...
}

Setting limit to 1 ensures that your query is not unnecessarily large. If you're just needing the total post count, then set limit to 1.

The since parameter is a unix timestamp (milliseconds since January 1, 1970) and is required to retrieve the total post count. Set this to 1 as setting it to 0 will throw an error.

More details: https://developers.facebook.com/docs/graph-api/reference/page/published_posts/


     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 till 250 and i used it last week