【问题标题】:Tweepy 401 error on search_recent_tweets <> BUT no 401 when I create_tweet?search_recent_tweets <> 上的 Tweepy 401 错误,但我 create_tweet 时没有 401?
【发布时间】:2022-01-13 08:06:16
【问题描述】:

为什么我可以创建一条推文并点赞一条没有 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​​ 文件却是。

【问题讨论】:

    标签: python authentication error-handling tweepy


    【解决方案1】:

    我遇到了和你一样的问题。
    也许这个问题已经解决了,为了确定,我描述了解决方案。

    我通过查看下面的答案解决了这个问题。
    Tweepy: tweepy.errors.Unauthorized: 401 Authorization Required

    请添加“user_auth=True”,如下所示

    client.search_recent_tweets(query=query, max_results=10,
    user_auth=True)
    

    至少,我可以这样解决。

    【讨论】:

      猜你喜欢
      • 2015-01-05
      • 2018-06-23
      • 2021-12-02
      • 2018-08-31
      • 2015-04-09
      • 2011-02-06
      • 2018-09-20
      • 2022-12-24
      • 1970-01-01
      相关资源
      最近更新 更多