对 YouTube 数据 API 的批量请求是否有效?
Do batch requests for the YouTube Data API work?
我向 https://www.googleapis.com/batch/youtube/v3 发送了一个请求,但我还是收到了 404。也许我发送的请求不正确,但端点很可能无法正常工作。
此外,我使用 Postman 来测试下一个信用点:
1. POST 请求 https://www.googleapis.com/batch/youtube/v3.
2. 将“Content-type”header设置为multipart/mixed.
3. 添加原始文本 body 作为 HTTP:
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=2222222&key=* HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=UTF-8
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=1111111&key=* HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=UTF-8
对 NodeJS 有什么建议吗?
YouTube 数据 API 版本 3 仅支持 batch processing 以下形式:
Batch processing – The v3 API supports one of the batch processing use cases that the v2 API had supported. The v3 API's channels.list
, channelSections.list
, guideCategories.list
, playlistItems.list
, playlists.list
, subscriptions.list
, videoCategories.list
, and videos.list
methods all support an id parameter, which can be used to specify a comma-delimited list of IDs (video IDs, channel IDs, etc.). Using those methods, you can retrieve a list of multiple resources with a single request.
根据文档,在 Channels.list
API 端点的情况下,您可以批处理多个调用,因为 id
属性 接受多个通道一次性 ID:
id (string)
The id
parameter specifies a comma-separated list of the YouTube channel ID(s) for the resource(s) that are being retrieved. In a channel
resource, the id
property specifies the channel's YouTube channel ID.
请注意,当要求 Videos.list
端点一次性生成 64 个视频的信息时,API 向我提供了以下响应(甚至只有 51 个产生了相同的响应):
ERROR 400: Bad Request
{
"error": {
"code": 400,
"message": "The request specifies an invalid filter parameter.",
"errors": [
{
"message": "The request specifies an invalid filter parameter.",
"domain": "youtube.parameter",
"reason": "invalidFilters",
"location": "parameters.",
"locationType": "other"
}
]
}
}
因此,此 API 端点 不接受超过 50 个 ID。很可能其他人也会以同样的方式运作。
我向 https://www.googleapis.com/batch/youtube/v3 发送了一个请求,但我还是收到了 404。也许我发送的请求不正确,但端点很可能无法正常工作。
此外,我使用 Postman 来测试下一个信用点:
1. POST 请求 https://www.googleapis.com/batch/youtube/v3.
2. 将“Content-type”header设置为multipart/mixed.
3. 添加原始文本 body 作为 HTTP:
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=2222222&key=* HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=UTF-8
GET https://www.googleapis.com/youtube/v3/channels?part=snippet&id=1111111&key=* HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=UTF-8
对 NodeJS 有什么建议吗?
YouTube 数据 API 版本 3 仅支持 batch processing 以下形式:
Batch processing – The v3 API supports one of the batch processing use cases that the v2 API had supported. The v3 API's
channels.list
,channelSections.list
,guideCategories.list
,playlistItems.list
,playlists.list
,subscriptions.list
,videoCategories.list
, andvideos.list
methods all support an id parameter, which can be used to specify a comma-delimited list of IDs (video IDs, channel IDs, etc.). Using those methods, you can retrieve a list of multiple resources with a single request.
根据文档,在 Channels.list
API 端点的情况下,您可以批处理多个调用,因为 id
属性 接受多个通道一次性 ID:
id (string)
Theid
parameter specifies a comma-separated list of the YouTube channel ID(s) for the resource(s) that are being retrieved. In achannel
resource, theid
property specifies the channel's YouTube channel ID.
请注意,当要求 Videos.list
端点一次性生成 64 个视频的信息时,API 向我提供了以下响应(甚至只有 51 个产生了相同的响应):
ERROR 400: Bad Request
{
"error": {
"code": 400,
"message": "The request specifies an invalid filter parameter.",
"errors": [
{
"message": "The request specifies an invalid filter parameter.",
"domain": "youtube.parameter",
"reason": "invalidFilters",
"location": "parameters.",
"locationType": "other"
}
]
}
}
因此,此 API 端点 不接受超过 50 个 ID。很可能其他人也会以同样的方式运作。