Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YouTube Data API v3 does not support 500 characters for ‘tags’ property of Video.snippet resource

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?

like image 318
Striker Star Avatar asked Oct 20 '22 07:10

Striker Star


2 Answers

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.

like image 56
Jinxmcg Avatar answered Oct 28 '22 21:10

Jinxmcg


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;
}
like image 42
haran Avatar answered Oct 28 '22 22:10

haran