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

使用YouTube Data API按日期范围拉取视频的问题求助

如何通过YouTube Data API按指定日期范围拉取自有频道视频?

我们正在使用Google的YouTube Data API拉取自有频道的视频,期望每日拉取一次指定日期范围的视频列表,但调用API时遇到以下问题:

问题1:全量拉取消耗配额导致超限

仅设置forMine=true未指定publishedBefore/publishedAfter时,会全量拉取所有视频,消耗大量QPS配额导致quotaExceeded。

请求详情:

curl --location --request GET 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&forMine=true&maxResults=50' \
--header 'Authorization: Bearer redacted' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: www.googleapis.com' \
--header 'Connection: keep-alive'

响应详情:

{
  "kind": "youtube#searchListResponse",
  "etag": "redacted",
  "nextPageToken": "redacted",
  "pageInfo": {
    "totalResults": 57,
    "resultsPerPage": 50
  },
  "items": [
    {…… #Skip detailed video specifics
          }
        },
        "channelTitle": "Qingquan Hou",
        "liveBroadcastContent": "none",
        "publishTime": "2025-07-15T03:39:33Z"
      }
    }
  ]
}

问题2:同时使用forMine和日期参数触发无效筛选错误

同时设置forMine=true与publishedBefore/publishedAfter时,返回invalidSearchFilter错误。

请求详情:

curl --location --request GET 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&forMine=true&maxResults=50&publishedAfter=2025-07-01T19:59:59Z' \
--header 'Authorization: Bearer redacted' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: www.googleapis.com' \
--header 'Connection: keep-alive'

响应详情:

{
  "error": {
    "code": 400,
    "message": "Request contains an invalid argument.",
    "errors": [
      {
        "message": "Request contains an invalid argument.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

问题3:仅指定日期范围无结果返回

不设置forMine=true仅指定日期范围时,无报错但返回结果为空。

请求详情:

curl --location --request GET 'https://www.googleapis.com/youtube/v3/search?part=snippet&type=video&maxResults=50&publishedAfter=2025-07-01T19:59:59Z' \
--header 'Authorization: Bearer redacted' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: www.googleapis.com' \
--header 'Connection: keep-alive'

响应详情:

{
  "kind": "youtube#searchListResponse",
  "etag": "redacted",
  "regionCode": "KR",
  "pageInfo": {
    "totalResults": 0,
    "resultsPerPage": 0
  },
  "items": []
}
解决方案

问题根源是search.list接口不支持同时使用forMine和日期筛选参数,这是接口的固有限制。换用videos.list接口即可实现按日期范围拉取自有频道视频的需求:

  1. 接口选择:使用videos.list替代search.list
  2. 参数配置:
    • 设置myRating=none,用于筛选自有频道的所有视频(替代search.list的forMine=true)
    • 添加publishedAfter和publishedBefore参数指定目标日期范围,格式需符合RFC 3339标准(如YYYY-MM-DDTHH:MM:SSZ)
    • 指定part=snippet(或你需要的其他字段),maxResults控制每页返回数量

示例请求:

curl --location --request GET 'https://www.googleapis.com/youtube/v3/videos?part=snippet&maxResults=50&myRating=none&publishedAfter=2025-07-01T19:59:59Z&publishedBefore=2025-07-02T19:59:59Z' \
--header 'Authorization: Bearer redacted' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Accept: */*' \
--header 'Host: www.googleapis.com' \
--header 'Connection: keep-alive'
  1. 分页处理:如果结果超过maxResults,使用响应中的nextPageToken参数继续拉取下一页数据,直到没有nextPageToken为止。

内容的提问来源于stack exchange,提问作者钟佩莹

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 14:41:00