我正在启动一个新的 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/