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

如何完整获取Mastodon账号所有关注者?API限制突破方案咨询

获取Mastodon账号完整关注者列表的方法

一、通过官方API分页遍历

Mastodon的accounts/followers接口单次返回上限为80条,但可以通过分页参数迭代获取所有关注者,核心逻辑是利用max_id参数逐步翻页:

  1. 首次调用接口时,传入limit=80获取前80条关注者;
  2. 从返回结果中提取最后一条数据的id,作为下一次请求的max_id参数;
  3. 重复上述步骤,直到接口返回空列表,即表示已获取全部关注者。

Python实现示例(使用官方SDK mastodon.py)

from mastodon import Mastodon

# 初始化客户端(需提前获取实例的访问令牌)
mastodon = Mastodon(
    access_token='你的访问令牌',
    api_base_url='https://你的实例域名'
)

all_followers = []
max_id = None

while True:
    # 分页获取关注者
    batch_followers = mastodon.account_followers(目标账号ID, max_id=max_id, limit=80)
    if not batch_followers:
        break
    all_followers.extend(batch_followers)
    # 更新下一页的max_id
    max_id = batch_followers[-1]['id']

print(f"共获取到 {len(all_followers)} 个关注者")

Python实现示例(使用原生requests库)

import requests

BASE_API_URL = 'https://你的实例域名/api/v1'
ACCESS_TOKEN = '你的访问令牌'
TARGET_ACCOUNT_ID = '目标账号ID'

all_followers = []
max_id = None
headers = {'Authorization': f'Bearer {ACCESS_TOKEN}'}

while True:
    params = {'limit': 80}
    if max_id:
        params['max_id'] = max_id
    # 发送请求
    response = requests.get(f"{BASE_API_URL}/accounts/{TARGET_ACCOUNT_ID}/followers", headers=headers, params=params)
    response.raise_for_status()
    batch_followers = response.json()
    if not batch_followers:
        break
    all_followers.extend(batch_followers)
    max_id = batch_followers[-1]['id']

print(f"共获取到 {len(all_followers)} 个关注者")

二、关于snscrape的可行性

snscrape对Mastodon关注者列表的支持并不理想,不推荐作为首选方案:

  • snscrape依赖Mastodon网页端的HTML结构,实例前端更新后抓取逻辑会直接失效;
  • 部分实例存在反爬机制,会限制snscrape的请求频率;
  • 无法保证数据的完整性和准确性,没有官方API那样可靠的分页迭代机制。

内容的提问来源于stack exchange,提问作者adinas

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 20:47:23