是你可以得到的圖片,但我會想象這取決於你使用的是什麼版本上。
使用im
RVM當前 紅寶石1.9.3-P194
> gem list
oauth (0.4.6)
oauth2 (0.8.0)
omniauth (1.1.0, 1.0.3)
omniauth-facebook (1.4.1, 1.4.0)
omniauth-google (1.0.1)
omniauth-google-oauth2 (0.1.13)
omniauth-oauth (1.0.1)
omniauth-oauth2 (1.1.0, 1.0.3)
omniauth-twitter (0.0.12)
我來到這裏出於不同的原因,這是由於該命名約定訪問配置文件屬性與各種教程中的配置屬性不同,因此我在完成登錄時遇到錯誤。實際上,在您的問題中,您可能會發現您將遇到同樣的問題。
問題是,谷歌有不同的財產名稱從FB,Twitter等,所以你必須考慮到這一點。
爲了找到我註釋掉的位的屬性,並且只是將響應丟棄了。像這樣。
elsif service_route == 'google_oauth2'
render :text => omniauth.to_yaml
return
這將輸出您的谷歌配置文件的細節,希望看起來像下面這樣。
--- !ruby/hash:OmniAuth::AuthHash
provider: google_oauth2
uid: '1234567'
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
name: Your Name
email: yourEmail
first_name: firstname
last_name: surname
image: https://animage
credentials: !ruby/hash:Hashie::Mash
token: aToken
expires_at: 123
expires: true
extra: !ruby/hash:Hashie::Mash
raw_info: !ruby/hash:Hashie::Mash
id: '123456'
email: YourEmail
verified_email: true
name: YourName
given_name: Name
family_name: surname
link: https://plus.google.com/blah
picture: https://lh6.googleusercontent.com/blah blah
gender: male
birthday: ''
locale: en-GB
正如你所看到的參數名稱不同,擺脫USER_INFO,而是有信息。
您還會注意到,你有圖片:和圖像:所以雖然我沒有嘗試這樣做我會假設,這是你的個人資料圖片。
elsif service_route == 'google_oauth2'
omniauth['info']['email'] ? email = omniauth['info']['email'] : email = ''
omniauth['info']['name'] ? name = omniauth['info']['name'] : name = ''
omniauth['uid'] ? uid = omniauth['uid'] : uid = ''
omniauth['provider'] ? provider = omniauth['provider'] : provider = ''
omniauth['info']['image'] ? image = omniauth['info']['image'] : image = ''
來自Omniauth文檔:「Google對於保持授權和認證是非常嚴格的,它們沒有端點直接獲取用戶的個人資料,我們可以*從聯繫人提要中獲取他們的姓名和電子郵件,然而。」所以看起來我無法做到這一點。也許只有使用Google+集成。 – rapcal