0
votes

I'm trying to get insights from facebook for some pages I have admin rights to. I'm able to get the correct data with the graph API but when I try with FQL I get an empty JSON object. Any idea what the problem may be?

I think the query is correct because I do not get any 400/500 errors. I also think the permissions are correct because I'm using the same framwork with the graph API solution and it works fine. Maybe you need additional permissions to use FQL? I have manage_pages and read_insights.

I'm implementing with basic text replacement on the template URIs from facebook's documentation.

EDIT: I think the problem may be that I don't actually have the read_insights permission. I do have the manage_pages permission. Perhaps this explains why I can access insights through Graph API but not FQL?

Graph API query:

string insight_str = "https://graph.facebook.com/APP_ID/insights/FIELD/FREQ?access_token=ACCESS_TOKEN";

string url = insight_str.Replace("FIELD", "page_impressions").Replace("FREQ","day").Replace("APP_ID", accounts[i].id).Replace("ACCESS_TOKEN", accounts[i].access_token);

https://graph.facebook.com/xxxxxxxx/insights/page_impressions/day?access_token=xxxxxxxx

Graph API parsed JSON result:

page_impressions
    2011-12-28  412
    2011-12-29  971
    2011-12-30  373

FQL query:

string query_str = "https://graph.facebook.com/fql?q=QUERY&access_token=ACCESS_TOKEN";

string query = "SELECT+metric,value+FROM+insights+WHERE+object_id=APP_ID+AND+metric='FIELD'+AND+end_time=1322722800+AND+period=86400";

string url = query_str.Replace("QUERY",query).Replace("FIELD","page_impressions").Replace("APP_ID",accounts[i].id).Replace("ACCESS_TOKEN",accounts[i].access_token);

https://graph.facebook.com/fql?q=SELECT+metric,value+FROM+insights+WHERE+object_id=xxxxxxxx+AND+metric='page_impressions'+AND+end_time=1322722800+AND+period=86400&access_token=xxxxxxxx

FQL JSON result:

{"data":[]}
2

2 Answers

1
votes

I have the same problem with Facebook C# SDK version 5.4.1 and 5.3.2 (see my post Error with FQL query with library 5.4.1)

I always receive an empty response like you.

You must have the read_insights permission.

0
votes

I think the end time in your example is slightly off. It needs to fall exactly at midnight PST. I obtained a value once I moved the time forward an hour, to 1322726400.