shoujo_sm
shoujo_sm

Reputation: 3203

RUBY ON RAILS -Retrieve "Likes" from facebook api pages

I am trying to get the likes from a company pages (coca-cola) I used this code but console report error "no such file and directory"

def facebook_likes()
 data = open("http://graph.facebook.com/40796308305").read
 data = JSON.parse(data)
 @likes = data['likes']

end

Upvotes: 1

Views: 1087

Answers (1)

Jeff Smith
Jeff Smith

Reputation: 902

Try something like this:

require 'net/http'
def facebook_likes
  uri = URI("http://graph.facebook.com/40796308305")
  data = Net::HTTP.get(uri)
  @likes = JSON.parse(data)['likes']
end

Upvotes: 3

Related Questions