【发布时间】:2022-01-20 20:08:34
【问题描述】:
我正在尝试从 geeksforgeeks 复制此 sn-p,但它使用 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.
这是我的:
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, access_token_secret=ACCESS_TOKEN_SECRET)
user = client.get_user(screen_name)
id = user.id_str
print(id)
当我运行我的时,它返回此错误:
TypeError: get_user() 接受 1 个位置参数,但给出了 2 个。
你能告诉我我错过了什么吗?先谢谢了。
【问题讨论】:
标签: python twitter tweepy twitterapi-python