📜  Python Tweepy – 获取用户 ID

📅  最后修改于: 2022-05-13 01:54:40.409000             🧑  作者: Mango

Python Tweepy – 获取用户 ID

在本文中,我们将了解如何获取用户的 ID。 ID 是 Twitter 帐户的唯一标识标记。 ID是Twitter给用户的,用户不能选择或更改自己的ID。

示例 1:考虑以下配置文件:

上述个人资料的网名是 geeksforgeeks。

# import the module
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 = "geeksforgeeks"
  
# fetching the user
user = api.get_user(screen_name)
  
# fetching the ID
ID = user.id_str
  
print("The ID of the user is : " + ID)

输出 :

The ID of the user is : 57741058

示例 2:考虑以下配置文件:

上述个人资料的网名是 PracticeGfG。

# the screen name of the user
screen_name = "PracticeGfG"
  
# fetching the user
user = api.get_user(screen_name)
  
# fetching the ID
ID = user.id_str
  
print("The ID of the user is : " + ID)

输出 :

The ID of the user is : 4802800777