Skip to content

Instantly share code, notes, and snippets.

@yuki24
Created October 11, 2012 14:07
Show Gist options
  • Save yuki24/3872533 to your computer and use it in GitHub Desktop.
Save yuki24/3872533 to your computer and use it in GitHub Desktop.
how to check if the user likes the given url/id of the page or not.
@client = Koala::Facebook::API.new(access_token)
# Check if the user likes the given url or not.
url = "http://example.com"
@client.fql_query("SELECT url FROM url_like WHERE user_id=me()").map do |like|
like["url"]
end.include?(url)
# Get how many likes the url got.
@client.fql_query("SELECT like_count FROM link_stat WHERE url=\"#{url}\"")["like_count"]
# Check if the user likes the page specified by the id or not.
page_id = 19765981
@client.fql_query("SELECT uid FROM page_fan WHERE page_id=#{page_id} and uid=me()").present?
@gotva
Copy link

gotva commented Dec 20, 2012

@client.fql_query("SELECT url FROM url_like WHERE user_id=me()")
can be improved
@client.fql_query("SELECT url FROM url_like WHERE user_id=me() AND url=\"#{url}\"")

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