YouTube's API will return a confusing error code if you use a language code which YT does not support.
PUT https://www.googleapis.com/youtube/v3/videos?part=snippet&key={YOUR_API_KEY}
{
"id": "GV40JxaAHdI",
"snippet": {
"title": "3 Days on the Missouri Riv",
"categoryId": "27",
"defaultLanguage": "nb"
}
}
'nb' is 'Norwegian Bokmål'. Youtube only accepts 'no' for 'Norwegian'.
{
"error": {
"errors": [
{
"domain": "youtube.video",
"reason": "invalidVideoMetadata",
"message": "The request metadata is invalid.",
"locationType": "other",
"location": "body"
}
],
"code": 400,
"message": "The request metadata is invalid."
}
}
YouTube's documentation on error codes is incomplete/deceptive in this case.
They say that invalidVideoMetadata
means:
The request metadata is invalid. This error occurs if the request updates the snippet part of a video resource but does not set a value for both the snippet.title and snippet.categoryId properties.
In this request, I've provided proper values for those fields. The error is that the snippet contains an unrecognized language code.
to verify, i re-issued the same request, changing only the language code.
PUT https://www.googleapis.com/youtube/v3/videos?part=snippet&key={YOUR_API_KEY}
{
"id": "GV40JxaAHdI",
"snippet": {
"title": "3 Days on the Missouri Riv",
"categoryId": "27",
"defaultLanguage": "en"
}
}
{
"kind": "youtube#video",
"etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/wjuLYtR1rIhaz9K9brVVJSpdwyg\"",
"id": "GV40JxaAHdI",
"snippet": {
"publishedAt": "2015-07-09T16:03:09.000Z",
"channelId": "UCEX9BscEMpJfaASiewenbYg",
"title": "3 Days on the Missouri Riv",
"description": "",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/GV40JxaAHdI/default.jpg",
"width": 120,
"height": 90
},
"medium": {
"url": "https://i.ytimg.com/vi/GV40JxaAHdI/mqdefault.jpg",
"width": 320,
"height": 180
},
"high": {
"url": "https://i.ytimg.com/vi/GV40JxaAHdI/hqdefault.jpg",
"width": 480,
"height": 360
}
},
"channelTitle": "Alex Dean",
"categoryId": "27",
"liveBroadcastContent": "none",
"defaultLanguage": "en",
"localized": {
"title": "3 Days on the Missouri Riv",
"description": ""
},
"defaultAudioLanguage": "en"
}
}
use only language codes supported by YouTube, which can be discovered via Youtube's i18nLanguages api
Thanks