简体   繁体   English

如何从twitter gem获取用户名?

[英]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_userTwitter::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.

相关问题 当用户已经登录时,如何使用Twitter gem和Omniauth gem获取用户的访问令牌? - How do I fetch the access token for a user using the Twitter gem and the Omniauth gem when the users is already logged in? 对于 rails 上的 twitter gem,我如何有效地调用 user_timeline 并为多个用户抓取推文? - For the twitter gem on rails, how do I efficiently call user_timeline and grab tweets for multiple users? 您如何遍历Twitter gem用户时间轴? - How do you iterate through Twitter gem user timeline? 如何使用omniauth gem获取Twitter用户ID? - How to use omniauth gem to get twitter user id? 我可以使用Twitter gem从多个Twitter名称中同时提取Twitter .user数据吗? - Can I use the Twitter gem to pull Twitter .user data from multiple Twitter names at the same time? twitter gem并传递用户名和密码 - twitter gem and passing user name and password 如何从使用twitter-Bootstrap-rails gem切换为使用普通Bootstrap - How do I switch from using the twitter-Bootstrap-rails gem to using normal Bootstrap 如何从gem内部获取Rails中的环境变量? - How do I get environment variables in Rails from inside a gem? Twitter gem的用户时间轴不起作用 - User timeline from twitter gem not working 如何使用 oauth gem 和 twitter 1.0.0 gem 对 Rails 应用程序中的用户进行身份验证? - How do I authenticate users in a Rails app with the oauth gem and twitter 1.0.0 gem?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM