I’m using Omniauth-Twitter with Device.
Twitter API gives me
{
"id": 2244994945,
"id_str": "2244994945",
"name": "TwitterDev",
"screen_name": "TwitterDev",
"location": "Internet",
"profile_location": null,
"description": "Developer and Platform Relations @Twitter. We are developer advocates. We can't answer all your questions, but we listen to all of them!",
"url": "http://twitter.com",
"entities": {
"url": {
"urls": [
{
"url": "https://twitter.com",
"expanded_url": "https://dev.twitter.com/",
"display_url": "dev.twitter.com",
"indices": [
0,
23
]
}
]
},
"description": {
"urls": []
}
},
.....
and I need to get the expanded_url for my website field, but it is in kinda array, how do I get that data?
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_create do |designer|
user.provider = auth.provider
user.uid = auth.uid
user.username = auth.info.nickname
user.website = HERE_I_NEED_USERS_WEBISTE_INFO
end
end
2
Answers
adding this to my designer.rb worked!
Lets suppose you have that twitter data in a variable called
twitter_data
. if it has the above structure, you’d be able to get to theextended_url
this way:I’d recommend trying this in the console with some real data and seeing what you get.
Edit:
According to the
omniauth-twitter
gem doco, you can get all this info from the authentication hash.and it looks like you’d be able to get the relevant url like this: