简体   繁体   中英

How do I get the user's name from the twitter gem?

I know this is a basic RTFM question but I'm pretty new to rails so any advice on R'ing TFM would be appreciated too.

I'm trying to do a proof of concept with the twitter gem in rails. I can create a client:

Twitter.configure do |config|
  config.consumer_key = TWITTER_KEY
  config.consumer_secret = TWITTER_SECRET
  config.oauth_token = omniauth['credentials']['token']
  config.oauth_token_secret = omniauth['credentials']['secret']
end
client = Twitter::Client.new

and now I would like to get the user's name with 'client'. Can anyone tell me what method will return the client's name? Also, as I mentioned above, I really should be able to figure this out from the rdocs but I'm still learning how to read them. Any help in understanding their structure would be really helpful too.

Thanks!

Ok, so I managed to figure out that current_user is a method on Twitter::Client . It sounded like what I needed so I added the following debug code to see if I couldn't figure out what it's structure was:

logger.debug "\n\t " + client.current_user.to_yaml + "\n\n"

This gave me a nicely formatted look into the structure of current_user which led me to client.current_user.name .

I still can't figure out how to grok this from the rdocs but converting an object to_yaml seems like a decent technique for figuring out it's structure.

Again, any improvements on how to figure out this type of issue would be greatly appreciated.

Thanks!

该属性的名称是“screen_name”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM