[英]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. 我知道这是一个基本的RTFM问题,但是我对Rails还是很陌生,因此,对R'ing TFM的任何建议也将不胜感激。
I'm trying to do a proof of concept with the twitter gem in rails. 我正在尝试用rails中的twitter gem进行概念验证。 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'. 现在我想用'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. 另外,如上所述,我确实应该能够从rdocs中弄清楚这一点,但我仍在学习如何阅读它们。 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
. 好的,所以我设法弄清楚current_user
是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
. 这给了我一个很好的格式化的current_user结构的外观,它引导我到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. 我仍然无法弄清楚如何从rdocs中解决这个问题,但转换对象to_yaml
似乎是一个很好的技术来确定它的结构。
Again, any improvements on how to figure out this type of issue would be greatly appreciated. 再次,非常感谢如何找出这类问题的任何改进。
Thanks! 谢谢!
该属性的名称是“screen_name”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.