Facebook API get number of posts? - facebook

Given a page access token, how can get the total number of posts day by day?

You can query the FQL insights table: http://developers.facebook.com/docs/reference/fql/insights/
the insight you're looking for in in the Page Content section of that link.
However, that is an insight that is being deprecate on 2/15. So be sure to get your data quick. It's being removed from Facebook. I don't know why.

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/

Related

Can we get the share count of a post in fb using graph api v2.3?

I need to get the shares count of a particular post in fb uisng graph api.
I could'nt find any method to do so. I have followed the link below.
https://developers.facebook.com/docs/graph-api/reference/v2.3/object/sharedposts
It returns the data of the shared posts in pagination format.
Is there any way to get the total count of the shares without fetching the whole data and without paginating within the data?
Please suggest!!
Just the field shares should give you the number of shares for a POST_ID
[POST_ID]?fields=shares
Sample data from my feed
{
"shares": {
"count": 1
},
"id": "POST_ID",
"created_time": "2015-04-29T09:07:12+0000"
}
Get shares count :
114916098537132_1265715836790480?fields=shares
Bonus [ Get likes + shares + comments ]
114916098537132_1265715836790480?fields=shares,likes.summary(true),comments.summary(true)
Improved version ( add limit(0) to removes list of likes and get only summary ):
114916098537132_1265715836790480?fields=shares,likes.limit(0).summary(true),comments.limit(0).summary(true)

How to get shares count for a Photo in Facebook?

I want to get comments count, likes count and shares count for a page posts. I have their IDs and I'm trying to figure something out with the Graph API or FQL, but in vain.
For regular posts I can query the stream FQL table and I get the comment_info, like_info structures and shares_count variable.
For posted photos I can query the photo table and I get from there comment_info and like_info, but it lacks the shares_count.
I tried using Graph api like that: GET /550045508388715 and it returns a ton of information, but nothing related to share count.
I've googled that issue, but did not found any relevant solution.
Instead of GET /ID use GET /POST_ID to get the shares count (if >1). You'll get the result as-
"shares": {
"count": x
}
Note- the Post ID is generally: USERID_PHOTOID ORPAGEID_PHOTOID

Retrieving page_fans using FQL from Insights table

I m trying to retrieve the page_fans using the following FQL query (Insights Table).
SELECT metric, value FROM insights WHERE object_id=182929845081087 AND metric='page_fans' AND end_time=1334905200 AND period=86400
But I just get blank data , when I make the above query.
{
"data": [
]
}
I m able to retrieve the other metrics by just changing the metric value in the above query.
For Eg. I get the page_engaged_users by just changing the metric value in the above query.
SELECT metric, value FROM insights WHERE object_id=182929845081087 AND metric='page_engaged_users' AND end_time=1334905200 AND period=86400
{
"data": [
{
"metric": "page_engaged_users",
"value": 35
}
]
}
What is wrong with the first query in which I m trying to retrieve the page_fans ??
And I know that I can retrieve page_fans using other ways as well !!
If you look at the insights documentation, notice in the last column that the page_fans metric is only available for the lifetime period. Change your query to period=0 or `period=period('lifetime') and you'll get data.
If you want the new fans added on a given day, use the page_fan_adds metric with period('day').
If you request any other period, you will either get an error or no data (which means someone other than you can request that metric for a different period).
The other problem could be that you are requesting data that is too recent. In your query, you're looking at 2012-04-20, so you should be fine. When I tested this, I got no data if I used a date greater than 2012-09-15 (on 2012-09-18).

Trying to get Insights with FQL-query but getting no data

I'm trying to get some statistical data from my page using FQL like so:
SELECT metric, value FROM insights WHERE object_id=278942378807967 AND metric='page_fan_adds' AND end_time=1327903200 AND period = 2592000
However all that is returned is:
{
"data": [
]
}
I also tried different dates and periods, most of which I'm pretty sure there should be data presented...
You're probably missing a valid access token on your query to get the stats.
period can only be 86400 or period("day")

FQL return 0 as like count for few pages

While running FQL query for retrieving page like count, i get 0 count for few pages. For most pages count comes fine but for few its always 0
Steps to reproduce:
Hit the following query:
https://graph.facebook.com/fql?q=SELECT+url,normalized_url,share_count,like_count,comment_count,total_count,commentsbox_count,comments_fbid,click_count+FROM+link_stat+WHERE+url+IN+(select+page_url+from+page+where+page_id+in+(344556287396,127535033990841,77277900503,293373084463))+
Expected Behavior
Correct like count should be returned:
http: //www.facebook.com/heyne.verlag (16,546)
http: //www.facebook.com/nwbVerlag (3,422)
Actual Behavior:
0 count is returned
I have checked with 150 pages, and find that FQL return 0 like count for 50+ pages. Please help me to fix this issue
This was by design. I was querying links of pages that are on Facebook.
link_stat reflects the interaction of users with a website, e.g. example.com. I made to query the page table in order to get the like count and was able to get correct count