Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve AttributeError: 'Client' object has no attribute 'apply_auth'?

Tags:

python

tweepy

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'
like image 801
Firefoxer Avatar asked Oct 24 '25 04:10

Firefoxer


1 Answers

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)
like image 107
Mickaël Martinez Avatar answered Oct 26 '25 20:10

Mickaël Martinez