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

如何在Calendly中使用page token正确实现分页遍历获取全量数据

实现代码

import requests

# 替换为你自己的请求头配置
headers = {}
# 替换为你的实际接口初始请求地址
current_url = "https://api.calendly.com/event_types"
# 存储全量业务数据
all_collection_data = []

while current_url:
    response = requests.get(current_url, headers=headers, timeout=10)
    # 可选:请求异常时直接抛出错误,避免静默失败
    response.raise_for_status()
    res_json = response.json()
    
    # 合并当前页的业务数据
    all_collection_data.extend(res_json.get("collection", []))
    # 读取下一页地址,无下一页时会赋值为None,自动终止循环
    current_url = res_json.get("pagination", {}).get("next_page")

# 输出最终全量数据
print(f"共拉取到{len(all_collection_data)}条数据:")
print(all_collection_data)

注意事项

  • 如果接口有请求频率限制,可在循环末尾添加time.sleep(n)(需提前导入time模块),n替换为间隔秒数,避免触发限流
  • 如果需要保留每一页完整的响应结构而非仅提取collection内容,可将存储变量改为all_response = [],每次循环执行all_response.append(res_json)即可
  • 上述代码默认响应结构与你给出的示例一致,若后续接口字段有调整,对应修改取数字段即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 21:36:03