Last active
May 11, 2018 06:52
-
-
Save Stephanvs/a2ec6e32d5189bff317ed7fa6cc78c33 to your computer and use it in GitHub Desktop.
Widget to track facebook page metrics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'net/http' | |
require 'json' | |
# this job will track some metrics of a facebook page | |
# Config | |
# ------ | |
# the fb id or username of the page you’re planning to track | |
facebook_graph_username = ENV['FACEBOOK_GRAPH_USERNAME'] || 'foobugs' | |
SCHEDULER.every '1m', :first_in => 0 do |job| | |
http = Net::HTTP.new("graph.facebook.com") | |
response = http.request(Net::HTTP::Get.new("/#{facebook_graph_username}")) | |
if response.code != "200" | |
puts "facebook graph api error (status-code: #{response.code})\n#{response.body}" | |
else | |
data = JSON.parse(response.body) | |
if data['likes'] | |
if defined?(send_event) | |
send_event('facebook_likes', current: data['likes']) | |
send_event('facebook_checkins', current: data['checkins']) | |
send_event('facebook_were_here_count', current: data['were_here_count']) | |
send_event('facebook_talking_about_count', current: data['talking_about_count']) | |
else | |
printf "Facebook likes: %d, checkins: %d, were_here_count: %d, talking_about_count: %d\n", | |
data['likes'], | |
data['checkins'], | |
data['were_here_count'], | |
data['talking_about_count'] | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
div { | |
font-size: 25px; | |
background-color: #777; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div>Hello from Facebook</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment