Is it possible to get a twitter account's username from an instance of the Twitter REST 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 twitter gem documentation on rubydoc and looked at the Twitter API user object documentation but wasn't able to solve the problem. I did try using client.attributes, client.to_h and client.screen_name, but received an unknown method error.
For context, I'm currently working on a twitter bot that auto-replies to hashtags when it is looped 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.
Thanks for reading.
Taking a look at the documentation for the
clientobject of the twitter gem says it has ausermethod (Methods included from Users section) [1]. The documentation for theusermethod states it returns aTwitter::Userobject of the currently authenticated user [2]. This class inherits fromBasicUserwhich is where thescreen_namemethod exists [3].