views:

527

answers:

5

Hi, I am trying to get a facebook fql query to work using the browser, I have a valid oauth token (I can make graph api calls with it).

Here is the url I tried:

https://api.facebook.com/method/fql.query?query=SELECT metric, value FROM insights WHERE object_id=89192912655 AND end_time=1280430050 AND period=86400 AND metric='page_fans'&access_token=?

I also tried running the fql query through a sql encoder first:

https://api.facebook.com/method/fql.query?query=SELECT%20metric%2C%20value%20FROM%20insights%20WHERE%20object_id%3D89192912655%20AND%20end_time%3D1280430050%20AND%20period%3D86400%20AND%20metric%3D'page_fans'&access_token=?

I tried a few other metrics, I can get the metrics via the graph api as well, so I know they are there.

Im sure im doing something dumb, but I have been stumped on this for a while now! Every call just returns this:

<?xml version="1.0" encoding="UTF-8"?>
<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true"/>

Maybe my dates are a problem, I used this to get the date: (ruby)

t = Time.now
=> Tue Aug 03 15:00:50 -0400 2010
>> t = t - 5.days
=> Thu Jul 29 15:00:50 -0400 2010
>> t.to_i
=> 1280430050

any ideas?

A: 

If you want to know the number of fans a facebook page has, use something like:

https://graph.facebook.com/cocacola

The response contains a fan_count property.

Roger
Roger, thanks, I know I can get the data there, just want to see fql working for other reasons, this is one data element im sure should be there, so used that as an eample.
Joelio
+1  A: 

The response you're seeing is an empty response which doesn't necessarily mean there's no metric data available. A few ideas what might cause this:

  • Are you using a user access token? If yes, does the user own the page? Is the 'read_insights' extended permission granted for the user / access token? How about 'offline_access'?
  • end_time needs should be specified as midnight, Pacific Time.
  • Valid periods are 86400, 604800, 2592000 (day, week, month)
  • Does querying 'page_fan_adds' metric yield meaningful results for a given period?

While I haven't worked with the insights table, working with Facebook's FQL taught me not to expect error messages, error codes but try to follow the documentation (if available) and then experiment with it...

As for the date, use the following ruby snippet for midnight, today:

Date.new(2010,9,14).to_time.to_i

I also found the following on the Graph API documentation page:

Impersonation

You can impersonate pages administrated by your users by requesting the "manage_pages" extended permission.

Once a user has granted your application the "manage_pages" permission, the "accounts" connection will yield an additional access_token property for every page administrated by the current user. These access_tokens can be used to make calls on behalf of a page. The permissions granted by a user to your application will now also be applicable to their pages. (source)

Have you tried requesting this permission and use &metadata=1 in a Graph API query to get the access token for each account?

rgabo
Thanks, in my case I have now confirmed all 4 of these are ok, but I agree this is probably true in most cases. Thats for the clear examples
Joelio
+1 for suggesting to check for extended permission, was relieved to learn why my app was failing :).
Dr1Ku
A: 

I'm not sure the date is correct. do you really want the date as an integer? Usually SQL takes dates in db-format, so to format it you'd use:

Date.new(2010,9,14).to_s(:db)
(Time.now - 5.days).to_s(:db)
# or even better:
5.days.ago.to_s(:db)
Taryn East
+2  A: 

Hey guys, we have confirmed this bug. This is due to the end_time having to be aligned with day delimiters in PST in order for the Insights table to return any data. To address this issue, we introduced two custom functions you can use to query the insights table:

  1. end_time_date() : accept DATE in string form(e.g. '2010-08-01')
  2. period() : accept 'lifetime', 'day', 'week' and 'month'

For example, you can now query the insights table using:

SELECT metric, value FROM insights
WHERE object_id = YOUR_APP_ID AND
      metric = 'application_active_users' AND
      end_time = end_time_date('2010-09-01') AND
      period = period('day');

We will document about these functions soon, sorry for all the inconvenience!

P.S. If you don't want to use the end_time_date() function, please make sure the end_time timestamp in your query is aligned with day delimiters in PST.

Thanks!

Facebook Insights Team

Xdxter
this now works for me, just make sure whatever metric you are looking for you are using a supported period. Here is a list of supported periods: http://developers.facebook.com/docs/reference/fql/insights
Joelio