Skip to content

Instantly share code, notes, and snippets.

@aquarla
Created September 22, 2010 05:10
Show Gist options
  • Save aquarla/591182 to your computer and use it in GitHub Desktop.
Save aquarla/591182 to your computer and use it in GitHub Desktop.
FacebookのLike件数を取得…のはずが、https://api.facebook.com/method/fql.query?query=select like_count, total_count, share_count, click_count from link_stat where url="http://www.yahoo.co.jp" とかやればこんなことする必要もなかったので不要になったコードである
require 'open-uri'
require 'nokogiri'
def facebook_like_count(url)
open("http://www.facebook.com/plugins/like.php?layout=button_count&show_faces=true&width=120&action=like&colorscheme=light&href=#{url}",
"User-Agent" => "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6") do |html|
Nokogiri::HTML.parse(html.read).search("div.connect_widget_button_count_count").text.to_i rescue -1
end
end
# p facebook_like_count("http://www.yahoo.co.jp/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment