Created
October 11, 2012 14:07
-
-
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.
This file contains 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
@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? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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}\"")