python - Tweepy 在 search_recent_tweets <> 上出现 401 错误,但在 create_tweet 时没有出现 401 错误?

标签 python authentication error-handling tweepy

为什么我可以创建一条推文并点赞一条推文,而不会出现 401 错误?当我尝试搜索推文时,我收到了 401?

这是我的 create_tweet.py 文件(工作正常)

import tweepy
import config

# calling a client
client = tweepy.Client(
    consumer_key=config.consumer_key,
    consumer_secret=config.consumer_secret,
    access_token=config.access_token,
    access_token_secret=config.access_token_secret
)

response = client.create_tweet(text='twitter api testoooor')


print(response)

但是我的 search.py​​ 文件不断收到 401 错误:


import tweepy
import config

# calling a client
client = tweepy.Client(
    consumer_key=config.consumer_key,
    consumer_secret=config.consumer_secret,
    access_token=config.access_token,
    access_token_secret=config.access_token_secret
)

response = client.search_recent_tweets(query=query, max_results=10)

for tweet in response.data:
    print(tweet.id)

真的很奇怪,create_tweet.py 没有收到 401 错误,但我的 search.py​​ 文件却收到了。

最佳答案

我也遇到了同样的问题。确保将 bearer_token 传递给客户端

见下文:

client = tweepy.Client(consumer_key=api_key,
                    consumer_secret=api_key_secret,
                    access_token=access_token,
                    access_token_secret=access_secret_key,
                    bearer_token=bearer_token)

关于python - Tweepy 在 search_recent_tweets <> 上出现 401 错误,但在 create_tweet 时没有出现 401 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70693231/

相关文章:

r - 如何使用在hclust中使用的变量创建向量

r - 在group_by中调用cor函数的`The standard deviation is zero`错误

简化 2 个 pandas 列与条件相乘的 Pythonic 方法

python salesforce Beatbox : beatbox. _beatbox.SoapFaultError: 'INVALID_FIELD'

Python编程-从Excel工作表中查找无效记录

android - 无法在 Android 谷歌登录中从谷歌获取 token ID

android - 处理RxJava的onErrorReturn和OnErrorNotImplementedException

python - 尝试重新定位 geopandas 图例时出现错误 `No handles with labels`

javascript - 同构应用程序中的用户配置文件

java - 将 WAR 分配给 JBOSS 中的安全域