You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Tweepy v2获取粉丝列表时遭遇401未授权错误求助

解决Tweepy v2调用get_users_followers时的401未授权错误

已完成的初始化与用户ID获取

我已成功初始化Tweepy Client并获取自身用户ID,代码如下:

import tweepy

# 填入你的凭证信息
client = tweepy.Client(
    consumer_key=consumer_key,
    consumer_secret=consumer_secret,
    access_token=access_token,
    access_token_secret=access_token_secret
)
# 获取自身用户ID
me = client.get_me()
my_id = me.data.id

调用get_users_followers时出现401错误

尝试用tweepy.Paginator结合client.get_users_followers获取粉丝列表时,触发401未授权错误,相关代码及报错信息如下:

粉丝获取代码

# 获取粉丝列表
followers = []
for response in tweepy.Paginator(client.get_users_followers, my_id, max_results=1000):
    followers.extend(response.data)

报错信息

---------------------------------------------------------------------------
Unauthorized                              Traceback (most recent call last)
<ipython-input-45-2fa8b522e9f3> in <cell line: 3>()
      1 # Get followers
      2 followers = []
----> 3 for response in tweepy.Paginator(client.get_users_followers, my_id, max_results=1000):
      4     followers.extend(response.data)

3 frames
/usr/local/lib/python3.10/dist-packages/tweepy/client.py in request(self, method, route, params, json, user_auth)
     96                 raise BadRequest(response)
     97             if response.status_code == 401:
---&gt; 98                 raise Unauthorized(response)
     99             if response.status_code == 403:
    100                 raise Forbidden(response)

Unauthorized: 401 Unauthorized
Unauthorized

请求协助解决该401未授权问题。

内容的提问来源于stack exchange,提问作者Zabir Al Nazi Nabil

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 21:52:43