We have encountered an unexpected limitation of less than the documented maximum 500 characters for the video ‘tags’ property, both when entering Tags directly into the YouTube UI interactively or when using the Data API v3 video resource snippet object.
We are using the YouTube Data API v3 to interact with YouTube from an ASP.Net C# web application, which uses the Google APIs Client Library for .NET.
During testing we have noticed that 500 characters are supported for exclusively single keyword Tags, but when there are any spaces encountered within the keywords, such as for people's names for example, each space appears to have an overhead and the 500 character limit is unexpectedly exceeded as a result.
The YouTube documentation states that Tags should be up to a maximum length of 500 characters, and that the Tags field contains a comma separated list and commas between items in the list and spaces within Tags between the commas count towards the limit.
There is no mention of exactly how spaces are handled though, yet a single whitespace character seems to count towards the overall field size as more than a single non-whitespace character, effectively reducing the length of Tags that can be supported unexpectedly when spaces are involved.
Could anyone please advise regarding the aforementioned issue?
If a tag contains a space, the API server handles the tag value as though it were wrapped in quotation marks, and the quotation marks count toward the character limit. So, for the purposes of character limits, the tag Foo-Baz contains seven characters, but the tag Foo Baz contains nine characters.
Youtube add two quotes marks to every words with spaces
example: hello world // 10 letters + 1 space + 2 quotation marks = 13chars.
hello,world // 10 letters + 1 comma = 11chars.
In javascript I do the next validation to control that:
function tagsValidator (values) {
//calculate num spaces (youtube add 2 quotes mark by space)
var numSpaces = values.replace(/[^\s]/g,'').length,
numTags = values.split(",").length,
numChars = (numTags+(numSpaces*2));
if(numChars>500) return false;
return true;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With