I have omniauth set up correctly and I am able to parse several other provider responses, including some of the attributes for a YouTube user but I am not able to get the YouTube user’s link to their channel. Here is what the response looks like, I am trying to get the link on the last line:
--- !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
.
.
.
I can get to things like “nickname” at the top by doing this in my user model:
def add_omniauth(auth)
user.name = auth["info"]["nickname"]
end
But how on earth do I get to that URL at the very bottom? I tried:
user.link = auth["extra"]["user_hash"]["link"]["href"]
but to no avail. As a rails and ruby newbie, I appreciate the help.
Okay, so as it turns out, link: in the youtube response is an array. You can tell because it isn’t listed as a hash next to it. I learned that after speaking with a friend of mine over here. So in order to get that link at the bottom of the response: