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

TikTok Research API分页调用报错:search_id无效或已过期

关于TikTok Research API Query Videos接口的Search ID失效问题

我拥有TikTok研究账号,正在使用Query Videos API批量获取单日所有视频。按照API文档要求,首次调用后在后续请求中使用返回的cursor和search_id参数,但始终收到报错:Search Id 7414696757969294378 is invalid or expired。联系TikTok支持团队后未收到回复,恳请技术协助。

首次调用详情

Request body: {
    "method": "POST",
    "url": "https://open.tiktokapis.com/v2/research/video/query/?fields=id%2Cvideo_description%2Ccreate_time%2Cregion_code%2Cshare_count%2Cview_count%2Clike_count%2Ccomment_count%2Cfavorites_count%2Cmusic_id%2Chashtag_names%2Cusername%2Ceffect_ids%2Cplaylist_id%2Cvoice_to_text",
    "headers": {
        "User-Agent": "python-requests/2.32.3",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Authorization": {omitted},
        "Content-Type": "application/json",
        "Content-Length": "206"
    },
    "body": "{\"query\": {\"and\": [{\"operation\": \"EQ\", \"field_name\": \"hashtag_name\", \"field_values\": [\"election\"]}], \"start_date\": \"20230101\", \"end_date\": \"20230101\", \"max_count\": 5, \"search_id\": \"\", \"cursor\": 0}"
}
INFO:tik_tok_api:Response body: {
    "data": {
        "cursor": 5,
        "has_more": true,
        "search_id": "7414696757969294378",
        "videos": [<list of video objects>]
    },
    "error": {
        "code": "ok",
        "message": "",
        "log_id": "2024091504190332DAC901505CAC3E3B2E"
    }
}

第二次调用详情

INFO:tik_tok_api:Request body: {
    "method": "POST",
    "url": "https://open.tiktokapis.com/v2/research/video/query/?fields=id%2Cvideo_description%2Ccreate_time%2Cregion_code%2Cshare_count%2Cview_count%2Clike_count%2Ccomment_count%2Cfavorites_count%2Cmusic_id%2Chashtag_names%2Cusername%2Ceffect_ids%2Cplaylist_id%2Cvoice_to_text",
    "headers": {
        "User-Agent": "python-requests/2.32.3",
        "Accept-Encoding": "gzip, deflate",
        "Accept": "*/*",
        "Connection": "keep-alive",
        "Authorization": {omitted},
        "Content-Type": "application/json",
        "Content-Length": "225"
    },
    "body": "{\"query\": {\"and\": [{\"operation\": \"EQ\", \"field_name\": \"hashtag_name\", \"field_values\": [\"election\"]}], \"start_date\": \"20230101\", \"end_date\": \"20230101\", \"max_count\": 5, \"search_id\": \"7414696757969294378\", \"cursor\": 5}"
}
INFO:tik_tok_api:Response body: {
    "error": {
        "code": "invalid_params",
        "message": "Search Id 7414696757969294378 is invalid or expired",
        "log_id": "2024091504190471DF3E7577323038D625"
    }
}

可能的解决方案

  • 严格保持请求参数一致:后续分页请求必须完全复用首次请求的所有query条件(包括hashtag、日期范围、max_count等),任何参数的细微修改都会导致search_id失效
  • 缩短请求间隔:search_id有效期可能极短,首次请求返回后立即发起下一次请求,间隔控制在1秒以内
  • 首次请求省略search_id字段:不要传空字符串"",直接去掉该字段,避免生成异常的search_id
  • 验证URL编码:确保请求URL中的fields参数编码正确,避免因编码问题导致接口识别请求不一致
  • 重试策略:如果仍报错,重新发起首次请求获取新的search_id,再继续分页操作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 02:00:19