Reputation: 1407
I admin a certain facebook page.I am trying to get urls of posts with 1000+ likes.
I dont need to retrieve data for using it in app.I would want to manually copy paste links of posts with 1000+ likes from the output we get from Graph API explorer.I am a bit new to this.
I have tried searching in API docs for such query which filters as per like,but in vain.All i could find is how to retrieve all posts using this
https://graph.facebook.com/ilovetrolls/posts?access_token=
Is there any such query which lets us filter as per likes?
Upvotes: 3
Views: 1145
Reputation: 1321
You can probably use fql and you want a query like:
SELECT post_id, comments, like_info.like_count, message
FROM stream
WHERE source_id = 263738183707778 and like_info.like_count > 1000 and created_time > 1325376000
replace 1325376000 with the start time you want (given in a unix time stamp format here, for reference see http://en.wikipedia.org/wiki/Unix_time, this is currently set to 1st Jan 2012 00:00:00
the url it generates that you need to use is:
https://graph.facebook.com/fql?q=SELECT post_id, comments, like_info.like_count, message FROM stream WHERE source_id = 263738183707778 and like_info.like_count > 1000 and created_time > 1325376000&access_token=
using soemthing like limit = 50 will help fetch more posts. The number of posts is limited by what I read is a bug in the fql api. See Facebook FQL stream limit? Facebook FQL `like` table retuns max 100 rows?
The recommended thing to do is use the graph api instaed. Unfortunately the graph api doesn't have a straight way to filter based on number of likes.
One thing to possibly do is change the date range and run in a loop example where you iterate over date ranges setting an upper and lower limit for the created_time and either run it in a loop or perform a batch query
If you want to do it more reliably try something likes this (the following is a python script): replace YOUR_ACCESS_TOKEN_GOES_HERE with your access_token
import urllib2
import json
access_token = 'YOUR_ACCESS_TOKEN_GOES_HERE'
request = urllib2.Request('https://graph.facebook.com/263738183707778/?fields=feed.fields%28likes.summary%28true%29.limit%281%29%29.limit%28500%29&access_token='+access_token)
data = urllib2.urlopen(request).read()
data_parsed = json.loads(data)
for a in data_parsed['feed']['data']:
if 'likes' in a:
if int(a['likes']['summary']['total_count'])>1000:
print a['id'].replace('263738183707778_','https://www.facebook.com/ilovetrolls/posts/')
data_parsed = data_parsed['feed']
while 'paging' in data_parsed:
request = urllib2.Request(data_parsed['paging']['next'])
data = urllib2.urlopen(request).read()
data_parsed = json.loads(data)
for a in data_parsed['data']:
if 'likes' in a:
if int(a['likes']['summary']['total_count'])>1000:
print a['id'].replace('263738183707778_','https://www.facebook.com/ilovetrolls/posts/')
Upvotes: 3
Reputation: 3674
Facebook Graph API doesn't provide any such feature. Only way to do that is by using FQL query. You can use the following FQL query to retrieve this information:
SELECT post_id, like_info.like_count
FROM stream WHERE source_id = {Your Page Id}
and like_info.like_count > 1000 LIMIT 50
For example, the following query will return the posts which received more than 1000 likes for your page:
SELECT post_id, like_info.like_count
FROM stream WHERE source_id = 263738183707778
and like_info.like_count > 1000 LIMIT 50
NOTE: Using LIMIT 50
at the end of your FQL query will return greater number of posts in the output as compared to a normal query. I don't know the reason behind this. In fact, I believe that it's just because of the strange behavior of the Facebook API.
Upvotes: 1
Reputation: 858
You cant only do it through FQL query. So you can use this URL. Or Write your own FQL query in the input place.
Upvotes: 0