我正在尝试从 geeksforgeeks 复制此代码片段,只不过它使用 Twitter API v1.1 的 oauth,而我使用 API v2。
# 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)
OUTPUT:
The ID of the user is: 4802800777.
Run Code Online (Sandbox Code Playgroud)
这是我的:
import os
import tweepy
API_KEY = os.getenv('API_KEY')
API_KEY_SECRET = os.getenv('API_KEY_SECRET')
BEARER_TOKEN = os.getenv('BEARER_TOKEN')
ACCESS_TOKEN = os.getenv('ACCESS_TOKEN')
ACCESS_TOKEN_SECRET = os.getenv('ACCESS_TOKEN_SECRET')
screen_name = 'nytimes'
client = tweepy.Client(consumer_key=API_KEY, consumer_secret=API_KEY_SECRET, access_token=ACCESS_TOKEN, …Run Code Online (Sandbox Code Playgroud)