0

Using v2 of the API via: http://gdata.youtube.com/schemas/2007/categories.cat, I can see both assignable and deprecated video categories.

However, using the v3 google data API, I see all categories, but no flag indicating if they are usable as a category on a video upload. Case in point is the category labelled "Anime/Animation" (category 31). If you try to upload a video using this category, you will receive a "Bad Request" response from YT at the end of the upload process.

If you choose any of the categories in the "assignable" list as per the first URL, then the upload works. Here's a deprecated category using the Atom based API:

<atom:category term="Movies_anime_animation" label="Anime/Animation" xml:lang="en-US">
    <yt:deprecated/>
</atom:category>

Here's the same thing, in JSON, from the Google API Explorer:

{
"id": "31",
"kind": "youtube#videoCategory",
"etag": "\"g-RLCMLrfPIk8n3AxYYPPliWWoo/-p_eJg3ji5PiNMcZrzS4hNfl4gQ\"",
"snippet": {
    "channelId": "UCBR8-60-B28hp2BmDPdntcQ",
    "title": "Anime/Animation"
}

I've looked at the video.list v3 API docs, and also the raw JSON output from the same API. I can't see how I could differentiate between deprecated and assignable categories. Is this just plain missing from the API or have I missed something?

4

2 回答 2

1

您可以接收解析 XML 文档的可分配类别列表。这是一个关于PHP的例子:

$catURL = 'http://gdata.youtube.com/schemas/2007/categories.cat';
$cxml = simplexml_load_file($catURL);
$cxml->registerXPathNamespace('atom', 'http://www.w3.org/2005/Atom');
$result = $cxml->xpath('//atom:category/yt:assignable/..');

$categories = array();
foreach ($result as $row) $categories[(string)$row['term']] = (string)$row['label'];
于 2013-06-13T16:16:42.590 回答
0

对于偶然发现此问题的任何人:YouTube V3 API 现在返回一个可分配的标志与每个类别片段。

要求

curl \
  'https://www.googleapis.com/youtube/v3/videoCategories?part=snippet&regionCode=NL&key=[YOUR_API_KEY]' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

回复

{
    "kind": "youtube#videoCategory",
    "etag": "7mqChSJogdF3hSIL-88BfDE-W8M",
    "id": "17",
    "snippet": {
        "title": "Sports",
        "assignable": true,
        "channelId": "UCBR8-60-B28hp2BmDPdntcQ"
    }
}
于 2020-09-02T09:02:24.497 回答