简体   繁体   中英

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. 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.
The 1 positional argument being referred to in the error is self.
You probably want to pass username as the screen_name keyword argument instead.
See also the relevant FAQ section in Tweepy's documentation about this .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM