8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RubyAdvent Calendar 2012

Day 5

gem Koalaをつかってユーザーが特定のページに「いいね!」しているかどうかをチェック

Last updated at Posted at 2012-12-06

https://github.com/arsduo/koala
おなじみ、facebookのgraph APIをrubyでイジイジできるgem
チェックしたいユーザーのaccess_token(もちろんパーミッションで「いいね!」を取ってこれるようにしておかないとダメですが)があればOK
https://developers.facebook.com/tools/explorer
Graph APIエクスプローラーでとりあえず試せるので、「アクセストークンを取得」→「User Data Permissions」タブ「user_likes」にチェックが入っていることを確認し「Get Access Token」
アクセストークンをコピーしておく。

fb_like_or_not.rb
require "Koala"
client = Koala::Facebook::API.new(access_token)

#URL先を「いいね!」しているかそうでないかをチェック

url = "http://www.livlis.com/"
client.fql_query("SELECT url FROM url_like WHERE user_id=me()").map do |like|
  like["url"]
end.include?(url) #=> true

#おまけ。「いいね!」している数のチェック
client.fql_query("SELECT like_count FROM link_stat WHERE url=\"#{url}\"").first["like_count"] #=> 285
8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?