0

Total noob to this. I have set up a script that can send a tweet, all I want to do is print text before the enter message promt that displays the screen name of the account.

In my mind it would be something like

user_name = twitter.get_screen_name()

print(user_name)

I have loaded all the keys from my app etc.

I notice on varify_credentials it does have

u'screen_name': screenname
falsetru
  • 357,413
  • 63
  • 732
  • 636
Neil T
  • 11
  • 3

1 Answers1

1

As you already note, verify_credentials returns a representation of the user that includes both name and screen_name. Therefore your method could look like:

def get_screen_name(twitter):
    return twitter.verify_credentials()["screen_name"]

Then you can call it:

user_name = get_screen_name(twitter)
print(user_name)

Making this a method of the twitter instance of the Twython class would be more complicated.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437