I have an application which authenticates users with Facebook using omniauth. I am getting all the data I need for this including the access token. I am using the Koala gem to communicate with Facebooks graph API which is working fine. So I have the following:
models/authentication.rb
def facebook
@facebook ||= Koala::Facebook::API.new(oauth_token)
end
So using the usual koala commands works fine:
facebook.get_object("me") etc etc
I now want to pull in the users photos using something like:
facebook.get_object("me/photos")
This just returns an empty array. So I have looked into it and realised that I need to set the permission on Facebook developers site under permissions/User & Friend Permissions. This however doesn't seem to have any affect as when I run:
facebook.get_connections("me", "permissions")
I don't see the the user_photos permission in the returned array.
This is what I think is causing the issue, but not sure why it's not coming through.
Please let me know if there is any other information I could provide. Any help will be much appreciated. Many thanks
You should request proper permission when you are get oauth token from the facebook for your application, for example it is OmniAuth used code that sets the read_stream
, and user_photos
permissions to a request for a user. The file is config/initializers/omniauth.rb
:
Rails.application.config.middleware.use OmniAuth::Builder do
provider :facebook, :setup => true, :scope => 'read_stream, user_photos'
end