Retrieving page_fans using FQL from Insights table - facebook

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).

Related

Get total number of matches along with result in algolia

I am looking for something like FOUND_ROWS() in mysql select query in algolia results as I need to keep a track of how many total results to expect. Is there someway to get this in Algolia?
The proper way to obtain the number of results is to access the nbHits value which is available in the JSON response of every search call.

Facebook Graph Api: using limit with since and until

I am trying to use limit along with since and until in Graph Api call. In between a certain time interval, I have 2 uploaded photos. The query looks like this:
me/photos/uploaded?since=2009-12-31T18%3A30%3A00.000Z&until=2010-12-31T18%3A30%3A00.000Z&limit=200
This query has limit set as 200 , and it correctly returns the 2 photos. But the problem arises when I have a smaller value of limit, lets say 100. So basically a query:
me/photos/uploaded?since=2009-12-31T18%3A30%3A00.000Z&until=2010-12-31T18%3A30%3A00.000Z&limit=100
return me an empty json. Even though there are only two photos, a limit of 100 returns null. Any insights?

Query every liked object using FQL

I'm trying to query every object which the user has liked since joining facebook by running this query:
SELECT user_id, object_id, post_id FROM like WHERE user_id=me()
This query runs fine and returns some results, but the number of them is a lot less than I estimated. I tried it on different, real user accounts, and for a friend of mine who has joined facebook around 2006 the number of returned results is still only around 65.
I tried this query through the official javascript sdk and through the graph api explorer which gave identical results.
The documentation doesn't state any limit imposed upon querying the like table.
Is there anything, I should be aware when doing a query on this table?
Thank you very much!
According to this documentation :
Each query of the stream table is limited to the previous 30 days or
50 posts, whichever is greater, however you can use time-specific
fields such as created_time along with FQL operators (such as < or >)
to retrieve a much greater range of posts.
Although not explicitly mentioned in the doucmentation for likes, I guess this will be the same limit. So try to add created_time in a where clause.

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")

Facebook API get number of posts?

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/