简体   繁体   中英

Omniauth facebook - fetch friends

I am trying to configure omniauth-facebook to fetch user friends.

This is my configuration:

ActionController::Dispatcher.middleware.use OmniAuth::Builder do
    provider :facebook, "xxxxxx", "xxxxxxxx",
      :info_fields => 'friends'
end

I am using Rails 2.3.

I am using this code in view:

<div id="contacts">

</div>
<script type="text/javascript" charset="utf-8">

  $('contacts').innerHTML = '<%= request.env['omniauth.auth'].keys %>';
</script>

I am not sure why the script is not being executed, but when I copy:

  $('contacts').innerHTML = 'infouidcredentialsextraprovider';

in console after page has loaded it works replacing content of div with that text.

There is no error message in browser console.

Why script does not get executed? I tried with console.log too, and I had no luck.

The info_fields option is still new and so you will have to wait for a new release of the omniauth-facebook gem.

In the meantime, you can try using the master branch by changing your Gemfile to:

gem 'omniauth-facebook', :github => 'mkdynamic/omniauth-facebook'

As for debugging, you can get the information returned from facebook by adding the following as the first line of your callback controller:

raise request.env["omniauth.auth"].to_yaml

Now try to login and you'll be able to take a good look at the hash of nested hashes returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM