怎么没有 videoId 的类别?

How come there are no categories for a videoId?

我尝试使用 YT API 资源管理器获取视频 ID 的所有视频类别。

我怎么得到空的项目数组?

还有其他方法可以获取每个视频的视频类别吗?

我看到有 video.categoryId。这是一样的吗?如何将此 ID 转换为字符串?

根据官方文档,参数id of VideoCategories.list API端点的含义与您自己的理解相反:

id (string)
The id parameter specifies a comma-separated list of video category IDs for the resources that you are retrieving.

根据此规范,id 不能是给定 YouTube 视频的 ID。

通常,将视频上传到 YouTube 时需要类别 ID。那是因为要上传的视频Videos.insert API endpoint requires the API user to specify the category ID

因此,可以使用 VideoCategories.list 获取通过 regionCode 参数指定的区域代码下所有可用类别的列表:

regionCode (string)
The regionCode parameter instructs the API to return the list of video categories available in the specified country. The parameter value is an ISO 3166-1 alpha-2 country code.

然后 API 用户将选择 VideoCategories.list 返回的 ID 之一作为 属性 [=22] 的值传递给 Videos.insert =] 是 video resource 的一部分,he/she 将作为 HTTP 请求主体传递给后者 API 调用。


如果您有兴趣获取给定视频所属的视频类别——假设您的视频由 ID VIDEO_ID 标识——,那么您必须调用 Videos.list API endpoint passing to it VIDEO_ID as the value of the parameter id,用于查找,在从 API 检索到的视频资源中,对于 属性 的值:

snippet.categoryId (string)
The YouTube video category associated with the video. You must set a value for this property if you call the videos.update method and are updating the snippet part of a video resource.

请确认任何给定的视频都恰好附加了一个视频类别 ID(由 snippet.categoryId 指定);因此任何给定的视频都属于一个视频类别。