Skip to content

Instantly share code, notes, and snippets.

@gregology
Created March 19, 2013 14:47
Show Gist options
  • Save gregology/5196740 to your computer and use it in GitHub Desktop.
Save gregology/5196740 to your computer and use it in GitHub Desktop.
Facebook link stats

Setup

Put the facebooklinkstats.rb to jobs/facebooklinkstats.rb.

Add the code from facebooklinkstats.erb to the desired dashboard.

Preview

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-id="fblinkstat" data-view="List" data-unordered="true" data-title="FB link stats" data-moreinfo="for amnesty.ca links"></div>
<i class="icon-facebook icon-background"></i>
</li>
#!/usr/bin/env ruby
require 'net/http'
require 'json'
# The url you are tracking
sharedlink = URI::encode('amnesty.ca')
SCHEDULER.every '10m' do
fbstat = []
http = Net::HTTP.new('graph.facebook.com')
response = http.request(Net::HTTP::Get.new("/fql?q=SELECT%20share_count,%20like_count,%20comment_count,%20total_count%20FROM%20link_stat%20WHERE%20url=%22#{sharedlink}%22"))
fbcounts = JSON.parse(response.body)['data']
fbcounts[0].each do |stat|
fbstat << {:label=>stat[0], :value=>stat[1]}
end
send_event('fblinkstat', { items: fbstat })
end
@bwente
Copy link

bwente commented Aug 3, 2015

Does this now need an access token to get data?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment