I'm having trouble with new and old documentation of tweepy, it seems that everything that worked in previous versions, but there are a lot of changes, I have a problem making it work right now. Any ideas why I have this error?
import tweepy
client = tweepy.Client(bearer_token='[redacted]',
consumer_key='[redacted]',
consumer_secret='[redacted]',
access_token='[redacted]',
access_token_secret='[redacted]')
api = tweepy.API(client)
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text)
I get this error
AttributeError: 'Client' object has no attribute 'apply_auth'
First of all, you should IMMEDIATELY refresh all your personnal and applications tokens.
Anyone can access the Twitter API on your behalf, it's like sharing your password publicly.
About your question: the tweepy.Client is used to access the version 2 of the Twitter API, while the tweepy.API is used to access the version 1.1 of the Twitter api.
So you can use them side by side, but they can not be mixed that way.
A quick fix could be:
auth = tweepy.OAuth1UserHandler(
consumer_key, consumer_secret, access_token, access_token_secret
)
api = tweepy.API(auth)
public_tweets = api.home_timeline()
for tweet in public_tweets:
print(tweet.text)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With