Skip to content

Instantly share code, notes, and snippets.

@zetavg
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save zetavg/713adcf7fc23245671e5 to your computer and use it in GitHub Desktop.

Select an option

Save zetavg/713adcf7fc23245671e5 to your computer and use it in GitHub Desktop.
get commenters from FB post.
require 'net/http'
require 'json'
post_id = ARGV[0]
access_token = ARGV[1]
uri = URI("https://graph.facebook.com/v2.2/#{post_id}/comments?limit=5000&access_token=#{access_token}")
body = Net::HTTP.get(uri)
data = JSON.parse(body)
commenters = data['data'].map { |d| d['from'] }
commenters.reject! { |c| !c['category'].nil? }
commenters.map! { |c| { fbid: c['id'], name: c['name'] } }
target = File.new('data.js', 'w')
target.write("var data = #{commenters.to_json} ;")
target.close
p 'ok'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment