Get username from client

12 views
Skip to first unread message

Eileen

unread,
Mar 10, 2018, 6:54:42 PM3/10/18
to Twitter Ruby Gem
Is it possible to get a twitter account's username from a Twitter client?  Specifically, I would like to get the name for the twitter account associated with the client's access tokens and secrets.  I searched through the documentation on rubydoc but wasn't able to find anything.  I did try using attributes and `client.screen_name`, but received an unknown method error.
For context, I'm currently working on a twitter bot that gives auto-replies in response to hashtags when it is called into a conversation.  We want to prevent the bot from tweeting at itself, so we are currently hard-coding in the bot name as an account not to tweet at.  It would be helpful if we could replace the hard-coded name with something like `client.account_name`.

Wynn Netherland

unread,
Mar 10, 2018, 7:41:31 PM3/10/18
to Twitter Ruby Gem
You should be able to use Client#verify_credentials:

irb(main):011:0> client.verify_credentials.screen_name
=> "pengwynn"

Eileen McFarland

unread,
Mar 11, 2018, 7:00:50 PM3/11/18
to twitter-...@googlegroups.com
That worked perfectly.  Thank you!

--
You received this message because you are subscribed to a topic in the Google Groups "Twitter Ruby Gem" group.
To post to this group, send email to twitter-ruby-gem@googlegroups.com.
Visit this group at https://groups.google.com/group/twitter-ruby-gem.

Reply all
Reply to author
Forward
0 new messages