Home > Blockchain >  How to get twitter userID from username using tweepy?
How to get twitter userID from username using tweepy?

Time:01-26

I am getting error : help me I tried many times. But it's not showing id from username.

 for tweet in tweepy.Cursor(api..........:
     try:
        
        screen_name= "NFTfemmefatale"
        id = screen_name

        get = api.get_user(id)

        print("id:"   str (get))
        
      except:
        print("error")

CodePudding user response:

try this:

import tweepy
  
# assign the values accordingly
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
  
# authorization of consumer key and consumer secret
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  
# set access to user's access key and access secret 
auth.set_access_token(access_token, access_token_secret)
  
# calling the api 
api = tweepy.API(auth)
  
# the screen name of the user
screen_name = "yourname"
  
# fetching the user
user = api.get_user(screen_name)
  
# fetching the ID
ID = user.id_str
  
print("The ID of the user is : "   ID)

CodePudding user response:

It's not working . please, Can you check this coding?

enter image description here

  •  Tags:  
  • Related