Skip to content

Instantly share code, notes, and snippets.

@netconstructor
Forked from gregology/README.md
Created June 21, 2013 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netconstructor/5830657 to your computer and use it in GitHub Desktop.
Save netconstructor/5830657 to your computer and use it in GitHub Desktop.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment