簡體   English   中英

Tweepy 錯誤 Python 用戶名查找熱門推文

[英]Tweepy Error Python With Username Finding Top Tweet

我正在 Python 中使用 Tweepy 制作一個程序,它從用戶那里獲取最熱門的推文,但由於某種原因,當我嘗試運行該程序時它給了我一個錯誤。 這是我的代碼和我得到的錯誤。

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) 

這是我的錯誤:

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在 Tweepy v4.0.0 中更改為不再接受位置 arguments。
錯誤中引用的第一個位置參數是 self。
您可能希望將username作為screen_name關鍵字參數傳遞。
另請參閱Tweepy 文檔中關於此的相關常見問題解答部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM