does the facebook fql application insights table work? - facebook

I'm running a few fql queries to try and pull insights data into my own tables where i could display them. The problem is that nothing is returned- here is a sample query
SELECT metric, value FROM insights WHERE object_id='000' AND metric='application_stream_stories' AND end_time = end_time_date('2012-04-02') AND period=period('day')
This returns a pair of empty square brackets. It doesn't even return the column names with the zero value.
If i do another query- this time changing the metric- it returns a zero value json array
SELECT metric, value FROM insights WHERE object_id='000' AND metric='application_active_users' AND end_time = end_time_date('2012-04-02') AND period=period('month')
and the result-
[{"metric":"application_active_users","value":0}]
i have tried these queries use php and the fql console on facebook- does this table work (http://developers.facebook.com/docs/reference/fql/insights/#application_content) i have cycled through most of the metrics finding nothing working.

Yes it works, ensure you have the read_insights permission. If you don't you will get an empty array. application_active_users does not need read_insights only a valid access token.
Any valid access_token for the publicly available application_active_users metric
https://developers.facebook.com/docs/reference/fql/insights/

Related

FQL query for seeing page post impressions

Basicly what I am trying to do is to get the post impressions from a page that I am and admin for and own and from the Graph API explorer have permission to view the insights. However when i run this:
SELECT metric, value FROM insights WHERE object_id=10151215628833061 AND metric='post_impressions' AND end_time=end_time_date('2012-12-7') AND period=0
I have set the object id to equal the to the posts id and the period to 0 which is lifetime but have no success.
All i get back is this:
{
"data": [
]
}
Can not figure out whats wrong with this, does anyone know what I am doing wrong?
Your post was created yesterday, but you're asking for metrics as of a month ago. The post didn't exist then, so there is nothing to return.
Change your query to this:
SELECT metric, value FROM insights WHERE object_id= '82346848060_10151215911933061' AND
metric='post_impressions' AND period=0
You want to quote the object ID just in case a post you're querying contains an underscore.

FQL search public posts

I'm trying to do a search using FQL.
Using the Graph API, it works but there are more options using FQL.
Using something like
https://graph.facebook.com/search?q=myquery&access_token=mytoken
it work fine.
I'm looking for the equivalent in FQL.
What query I must write in here
https://api.facebook.com/method/fql.query?query=SELECT%20post_id%2C%20actor_id%2C%20target_id%2C%20message%20FROM%20stream&access_token=mytoken
The query above give me that
Parser error: unexpected end of query
I want to search in all public posts.
I've been looking everywhere but I did not found any solution.
Thanks.
For searching public posts for a string, you need to use the Graph API, and then filter those posts in your script. I don't think searching all public posts is possible in FQL. While FQL is more powerful, it is also more limited.
You are getting an error because you don't have a "WHERE" clause in your query. This is required in FQL.
The limit comes in because you must use at least one indexed column in your WHERE query. For the stream table you must specify either a post via post_id, a user via source_id or filter_key, or a live stream via xid. The indexed fields are marked with a * on the documentation site.
For instance, [this FQL][1]
SELECT post_id,actor_id,target_id,message FROM stream WHERE filter_key = 'others'
AND strpos(message, 'the') >= 0
will get you all posts that show on your access token owner's wall that have not been posted by the owner, with the string 'the' in them. That is the best you can get. If the post isn't visible on their wall, then you won't get the post.
If you try to leave out an indexed field, FQL will throw a 'Your statement is not indexable' error.
[1]: SELECT post_id,actor_id,target_id,message FROM stream WHERE filter_key = 'others' and strpos(message,'the') >=0

Facebook insights domain_widget_likes -> lifetime don't return results?

I'm doing a query to get the total likes for a domain and I am using the following:
https://api.facebook.com/method/fql.query?query=SELECT metric, value FROM insights WHERE object_id=xxxxxxxxx AND metric='domain_widget_likes' AND end_time=end_time_date('2011-08-27') AND period=period('lifetime')&access_token=xxxxxxxxx
I already claimed my domain, have the object id for my domain and installed an app to get access to insights and send the token.
But return nothing, if I try with period('day') the query works fine but I need all likes not only daily.
Anyone knows if it is a new rule on the insights data or is a bug?
Thanks a lot.
Are you able to use a wildcard % in the query like so (period LIKE period('%')):
https://api.facebook.com/method/fql.query?query=SELECT metric, value FROM insights WHERE object_id=xxxxxxxxx AND metric='domain_widget_likes' AND end_time=end_time_date('2011-08-27') AND period LIKE period('%')&access_token=xxxxxxxxx
String Comparison Functions Reference has more info on query wildcards, etc.

Use Facebook FQL to select the work information from the profile

I would like to get work place information of a user using FQL.
When I use the Graph API and get the User object, it contains work information, which is essentially a list of the work history. The list elements contain nodes of employer, location, description, etc...
The nodes appear to be pages internally. If I take the id of a node, e.g. from the employer, and use FQL to query a page with that page_id, I do get an object with corresponding information.
My question now is, how do I use FQL to get the same information without accessing the Graph API? What table stores the work-related information, for example how do I find all the page_id of the employers of a given user?
The reason I insist on using FQL only is performance. Of course I could access the Graph API for all the users in question and get the info that way, but I'm looking for an FQL-only solution.
You can get this information from FQL. Read the "user" table and look for the work field. The JSON data returned should be the same format as the one for Graph, i.e., the result is an array and each result should include an "employer" object with an "id" and "name" field.
You will need user_work_history or friends_work_history to access this field.

Facebook - max number of parameters in “IN” clause?

In Facebook query language(FQL), you can specify an IN clause, like:
SELECT uid1, uid2 FROM friend WHERE uid1 IN (1000, 1001, 1002)
Does anyone know what's the maximum number of parameters you can pass into IN?
I think the maximum result set size is 5000
It may seem like an odd number (so perhaps I miss counted, but it's close ~1), but I can not seem to query more than 73 IN items. This is my query:
SELECT object_id, metric, value
FROM insights
WHERE object_id IN ( ~73 PAGE IDS HERE~ )
AND metric='page_fans'
AND end_time=end_time_date('2011-06-04')
AND period=period('lifetime')
This is using the JavaSCript FB.api() call.
Not sure if there is an undocumented limit or it might be an issue of facebook fql server timeout.
You should check if there is a error 500 returned from FB web server which might indicate you are passing a too long GET statement (see Facebook query language - long query)
I realized my get was too long so instead of putting many numbers in the IN statement, i put a sub-query there that fetches those numbers from FB FQL - but unfortunately it looks like FB couldn't handle the query and returned an 'unknown error' in the JSON which really doesn't help us understand the problem.
There shoud not be a maximum number of parameters as there isnt in SQL IN as far as I know.
http://www.sql-tutorial.net/SQL-IN.asp
just dont use more parameters than you have values for the function to check because you will not get any results (dont know if it will give away an error as I never tried to).