[英]Tweepy Error Python With Username Finding Top Tweet
I'm making a program in Python, using Tweepy, that gets the top Tweet from a user, but for some reason it gives me am error when I try to run the program.我正在 Python 中使用 Tweepy 制作一个程序,它从用户那里获取最热门的推文,但由于某种原因,当我尝试运行该程序时它给了我一个错误。 Here is my code and my error I got.
这是我的代码和我得到的错误。
import tweepy
consumer_key = ""
consumer_secret = ""
access_token = ""
access_token_secret = ""
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
username='@username'
tweets_list= api.user_timeline(username, count=1)
tweet= tweets_list[0]
print(tweet.created_at)
print(tweet.text)
print(tweet.in_reply_to_screen_name)
Here is my error:这是我的错误:
Traceback (most recent call last):
File "main.py", line 10, in <module>
tweets_list= api.user_timeline(username, count=1) # Get the last tweet
File "/home/runner/elon-tweet/venv/lib/python3.8/site-packages/tweepy/api.py", line 33, in wrapper
return method(*args, **kwargs)
File "/home/runner/elon-tweet/venv/lib/python3.8/site-packages/tweepy/api.py", line 46, in wrapper
return method(*args, **kwargs)
TypeError: user_timeline() takes 1 positional argument but 2 were given
API.user_timeline
was changed in Tweepy v4.0.0 to no longer accept positional arguments. API.user_timeline
在 Tweepy v4.0.0 中更改为不再接受位置 arguments。
The 1 positional argument being referred to in the error is self.错误中引用的第一个位置参数是 self。
You probably want to pass username
as the screen_name
keyword argument instead.您可能希望将
username
作为screen_name
关键字参数传递。
See also the relevant FAQ section in Tweepy's documentation about this .另请参阅Tweepy 文档中关于此的相关常见问题解答部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.