【问题标题】:How to solve AttributeError: 'Client' object has no attribute 'apply_auth'?如何解决 AttributeError: \'Client\' object has no attribute \'apply_auth\'?
【发布时间】:2022-11-11 03:02:14
【问题描述】:

我在处理 tweepy 的新旧文档时遇到了问题,似乎所有在以前的版本中都可以正常工作,但是有很多变化,我现在很难让它工作。任何想法为什么我有这个错误?

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)

我收到这个错误

AttributeError: 'Client' object has no attribute 'apply_auth'

【问题讨论】:

  • 注意:编辑您的问题以删除您的 API 凭据不会使它们不可用。您的问题的旧版本仍然可用,并且仍然包含该信息。

标签: python tweepy


【解决方案1】:

首先,您应该立即刷新所有个人和应用程序令牌。

任何人都可以代表您访问 Twitter API,就像公开分享您的密码一样。

关于您的问题:tweepy.Client 用于访问 Twitter API 的版本 2,而 tweepy.API 用于访问 Twitter api 的版本 1.1。

所以你可以并排使用它们,但不能这样混合。

快速修复可能是:

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)

【讨论】:

    【解决方案2】:

    给定的代码给出错误,“未经授权:401未经授权 32 - 无法验证您的身份。”

    【讨论】:

      猜你喜欢
      • 2021-04-06
      • 2022-12-04
      • 1970-01-01
      • 2022-12-03
      • 1970-01-01
      • 1970-01-01
      • 2022-12-01
      • 2020-09-15
      • 2020-11-02
      相关资源
      最近更新 更多