FQL multiquery showing empty array - facebook-fql

i am usig Facebook fql.multiquery to fetch data with command line. like this
$queries = '{
**"query1" : "SELECT metric, value
FROM insights WHERE object_id=148945955209922
AND metric="application_active_users"
AND end_time=end_time_date("2011-12-10")
AND period=period("month")",
"query2" : "SELECT metric, value
FROM insights WHERE object_id=148945955209922
AND metric="application_active_users_city"
AND end_time=end_time_date("2011-12-10")
AND period=period("month")"
}';
But while running this code it is showing empty Array.
can anybody help me?

I would first start troubleshooting your access token. Ensure your access token has the appropriate permissions. Secondly, ensure the queries run independently of each other by running each one separately thru the normal FQL. You can play around with the FQL structure using the Graph API Explorer tool https://developers.facebook.com/tools/explorer

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.

does the facebook fql application insights table work?

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/

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.

Facebook fb:comments Graph API

i want to have facebook comments + my own website comments on my site.
The thing is when showing posts i want to show a comment count next to every single one(so my comments + facebook comments).
I know i can achieve this with https://graph.facebook.com/comments/?ids={PAGE_URL} but i have 100posts per page and i don't want to do this query a 100 times per page, also and more important is that i want to create a most commented widget where i currently have 1/4 of a million (250000) posts.
So basically my question is how i can access sort of a database on all comments left on my domain/site and sort them, that is manipulate them?
Here are some examples of ways you could do this:
FQL:
You can build your a JSON array of queries and then use the Rest API fql.multiquery method to run them. For example, this would be your JSON array of queries:
{
'query1': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/comment/')",
'query2': "select post_fbid from comment where object_id in (select comments_fbid from link_stat where url ='http://developers.facebook.com/docs/reference/fql/album/')"
}
Run this using the test console on the fql.multiquery page and you'll be able to see a response containing a list of post_fbids which you could then count using your favored counting method.
Graph API:
Here you can use a Batch Request to run all of your queries at once. So for a PHP Example you'd be doing:
curl \
–F ‘access_token=…’ \
-F ‘batch=[ \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL1}”}, \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL2}”}, \
{“method”: ”GET”, “relative_url”: ”comments/?ids={PAGE_URL3}”} \
]’\
https://graph.facebook.com
For as many pages as you want.
Note: Given that both APIs do have a bit of a delay before you'll get a response, obviously it's recommended to run them asynchronously so that you aren't causing your site load to delay significantly.
Try this:
Place the URL separated by commas, If you wanna fetch multiple calls using the graph API :
https://graph.facebook.com/comments/?ids=http://URL_1,http://URL_2,http://URL_n
I think for your use case FQL will suit the best : https://developers.facebook.com/docs/reference/fql/comment/ .
On the side note, if you wanna do multiple http calls using the graph API , its always good to do "Batch calls" as documented in the graph API documentation.

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.