我正确设置了omniauth,并且能够解析其他几个提供商的响应,包括YouTube用户的一些属性,但我无法获取YouTube用户到他们频道的链接。这是响应的样子,我正在尝试获取最后一行的链接:
--- !ruby/hash:OmniAuth::AuthHash
provider: youtube
uid: http://gdata.youtube.com/feeds/api/users/DLjkduRouoiweRktkkl
info: !ruby/hash:OmniAuth::AuthHash::InfoHash
uid: http://gdata.youtube.com/feeds/api/users/DLjkduRouoiweRktkkl
nickname: Example User
email: exampleuser@gmail.com
first_name: Example
last_name: User
image: http://lh3.googleusercontent.com/-7vCkdsSDAfsU/AAAAAAAAAAA/kjRe3kjk/s88-c-k/photo.jpg
description:
location: Example City CA, US
channel_title: Example User
subscribers_count: '66'
credentials: !ruby/hash:Hashie::Mash
token: kh58.lkjASDF93-W2-ADFJkjfdo498_W8IWnjWTWY
expires_at: 1354004818
expires: true
extra: !ruby/hash:Hashie::Mash
user_hash: !ruby/hash:Hashie::Mash
xmlns: http://www.w3.org/2005/Atom
xmlns$media: http://search.yahoo.com/mrss/
xmlns$gd: http://schemas.google.com/g/2005
xmlns$yt: http://gdata.youtube.com/schemas/2007
id: !ruby/hash:Hashie::Mash
$t: http://gdata.youtube.com/feeds/api/users/DLjkduRouoiweRktkkl
published: !ruby/hash:Hashie::Mash
$t: '2012-02-14T23:39:43.000Z'
updated: !ruby/hash:Hashie::Mash
$t: '2012-11-27T06:07:22.000Z'
category:
- !ruby/hash:Hashie::Mash
scheme: http://schemas.google.com/g/2005#kind
term: http://gdata.youtube.com/schemas/2007#userProfile
title: !ruby/hash:Hashie::Mash
$t: Example User
type: text
content: !ruby/hash:Hashie::Mash
$t: Example user channel description
type: text
link:
- !ruby/hash:Hashie::Mash
rel: alternate
type: text/html
href: http://www.youtube.com/channel/kljasdSDAF98324
.
.
.
通过在我的用户模型中执行此操作,我可以在顶部找到“昵称”之类的内容:
def add_omniauth(auth)
user.name = auth["info"]["nickname"]
end
但是我到底如何才能到达最底部的那个 URL?我试过了:
user.link = auth["extra"]["user_hash"]["link"]["href"]
但无济于事。作为 rails 和 ruby 新手,我感谢您的帮助。