Ruby on rails 3.2 Omniauth YouTube帮助解析响应
我已经正确设置了omniauth,并且我能够解析其他几个提供商的响应,包括YouTube用户的一些属性,但是我无法获取YouTube用户到他们频道的链接。下面是响应的样子,我正在尝试获取最后一行的链接:Ruby on rails 3.2 Omniauth YouTube帮助解析响应,ruby-on-rails-3.2,youtube-api,omniauth,Ruby On Rails 3.2,Youtube Api,Omniauth,我已经正确设置了omniauth,并且我能够解析其他几个提供商的响应,包括YouTube用户的一些属性,但是我无法获取YouTube用户到他们频道的链接。下面是响应的样子,我正在尝试获取最后一行的链接: --- !ruby/hash:OmniAuth::AuthHash provider: youtube uid: http://gdata.youtube.com/feeds/api/users/DLjkduRouoiweRktkkl info: !ruby/hash:OmniAuth::Aut
--- !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新手,我感谢您的帮助 好吧,事实证明,youtube响应中的link:是一个数组。您可以分辨,因为它旁边没有列为哈希。我和我的一个朋友在这里谈过之后才知道。因此,为了获得响应底部的链接:
self.url = auth["extra"]["user_hash"]["link"].first["href"]