3

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?

Rahul Shah
  • 1,387
  • 4
  • 22
  • 41

3 Answers3

3

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/')
Community
  • 1
  • 1
sj7
  • 1,291
  • 1
  • 12
  • 26
  • Thanks a lot for your ans....any tips whats this error? http://img.ctrlv.in/img/52c04e15eaf53.jpg – Rahul Shah Dec 29 '13 at 16:30
  • Alternatively you could look at fetching posts with the graph api and getting a summary of likes then later filtering them by number of likes. This will just ensure that you get all of the posts.Which language are you writing your code in? – sj7 Dec 30 '13 at 06:39
  • how to do that?English – Rahul Shah Dec 30 '13 at 06:57
  • lol....i feel so dumb....I am not writing the code for use in any app or something.....i just need to get a list of urls manually. :) – Rahul Shah Dec 30 '13 at 08:25
  • let me know if you need any more help – sj7 Dec 30 '13 at 10:35
  • I have reached till here i get this error http://img.ctrlv.in/img/52c196763c5df.jpg SyntaxError: multiple statements found while compiling a single statement ...any tips? – Rahul Shah Dec 30 '13 at 15:49
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/44172/discussion-between-user2417590-and-michel) – sj7 Dec 30 '13 at 16:47
  • hi,can you create a similar script for getting Instagram posts? I can give you 500 bounty again if u want.thanks a ton – Rahul Shah Apr 15 '18 at 21:52
1

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.

Rahil Arora
  • 3,644
  • 3
  • 26
  • 43
  • Seems the limit is around 500...can't help maybe....is there any way to select post url instead of post_id :) ? – Rahul Shah Dec 30 '13 at 08:27
  • If you are doing it manually, you just need to add the last 15 digits of the post_id to the URL `https://www.facebook.com/ilovetrolls/posts/`. For example, if the post_id is 263738183707778_567657616649165, then URL for that post would be https://www.facebook.com/ilovetrolls/posts/567657616649165. – Rahil Arora Dec 30 '13 at 08:57
0

You cant only do it through FQL query. So you can use this URL. Or Write your own FQL query in the input place.