为什么我可以创建一条推文并点赞一条推文,而不会出现 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/