如何使用twitter从用户名中获取twitter用户ID



我遇到错误:帮我吧,我试过很多次了。但它并没有显示用户名中的id。

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")

试试这个:

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)

最新更新