Can someone please tell me how to get one username from one id on tweepy? I have looked everywhere and can't find anything.
Go to www.twitter.com and sign in with your account. Then click on your profile picture at the top bar and select Settings and privacy from the drop-down menu. Open 'Your Twitter data' Tab.
Identifying the ID in the GUI : In order to get the ID of a status, we have to do the following : Identify the status ID of the status from the GUI. Get the Status object of the status using the get_status() method with the status ID. From this object, fetch the id attribute present in it.
If you want to retweet a Tweet with Tweepy using the Twitter API v2, you will need to make sure that you have your consumer key and consumer secret, along with your access token and access token secret, that are created with Read and Write permissions (similar to the previous example).
If you just have a user_id value you need to call the twitter API with the get_user(user_id) method. The returned User object will contain the username under screen_name.
# steps not shown where you set up api
u = api.get_user(783214)
print u.screen_name
If you already have the User object from another API call just look for the screen_name.
You can use this code to get user screen name or user id
To get user screen name from user id
In [36]: import tweepy
In [37]: consumer_key = Your_consumerkey
In [38]: consumer_secret = Your_consuersecret
In [39]: access_token = Your_access_token
In [40]: access_token_secret = Your_access_token_secret
In [41]: auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
In [42]: auth.set_access_token(access_token, access_token_secret)
In [43]: api = tweepy.API(auth)
In [48]: user = api.get_user(1088398616)
In [49]: user.screen_name
Out[49]: u'saimadhup'
To get user id from user screen name
In [46]: user = api.get_user(screen_name = 'saimadhup')
In [47]: user.id
Out[47]: 1088398616
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With