ruby-on-rails - 使用 Omniauth on Rails 3 检索 Google 个人资料图片

标签 ruby-on-rails ruby-on-rails-3 authentication omniauth

我正在启动一个新的 Rails 3 应用程序,使用 Omniauth 通过 Facebook、Twitter 和 Google 进行身份验证。我可以轻松地从 Facebook 和 Twitter 获取用户的头像,但无法找到从 Google 检索它的方法(如果存在)。

这是我用来构建身份验证哈希的代码:

omniauth['user_info']['email'] ? @authhash[:email] =  omniauth['user_info']['email'] : @authhash[:email] = ''
omniauth['user_info']['name'] ? @authhash[:name] =  omniauth['user_info']['name'] : @authhash[:name] = ''
omniauth['uid'] ? @authhash[:uid] = omniauth['uid'].to_s : @authhash[:uid] = ''
omniauth['provider'] ? @authhash[:provider] = omniauth['provider'] : @authhash[:provider] = ''

在 Twitter 和 Facebook 上,下一行获取头像或设置为默认值(如果未提供):
omniauth['user_info']['image'] ? @authhash[:image] =  omniauth['user_info']['image'] : @authhash[:image] = 'avatar.jpg'

这在谷歌上不起作用,我找不到任何关于它的文档。

有任何想法吗?

非常感谢!

最佳答案

尝试“Omniauth Google OAuth2 策略”,其中提交声明:

Returns name, first_name, last_name, image, email in info with :scope => 'userinfo.email,userinfo.profile'



您可以查看提交 here

关于ruby-on-rails - 使用 Omniauth on Rails 3 检索 Google 个人资料图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7044418/

相关文章:

ruby-on-rails - rails : Bootstrap Editing Forms CSS

ruby - 单一嵌套资源的正确路线

javascript - 我应该在 2019 年将我的 JWT 存储在哪里,localStorage 真的不安全吗?

validation - 在没有数据库的情况下验证 PostgreSQL 用户和密码

javascript - rails : stylesheet path in js file on production

ruby-on-rails - Rails_admin 显示对象名称而不是 ID

ruby-on-rails - 通过子域共享一个Cookie

ruby-on-rails - 用于临时应用程序与生产应用程序的不同 S3 存储桶

javascript - 使用 Chrome 开发者工具获取 XXX-xsrfstatemanager.js 文件的启动器

ruby-on-rails - 非空白字符的剥离方法?