I've noticed I get quite a bit of HTTP 400
faliures when trying to upload videos via:
https://developers.google.com/youtube/v3/docs/videos/insert
I am using the Go SDK from Google: code.google.com/p/google-api-go-client
The thing that the failed uploads have in common is that somewhere in the videos snippet data (title/description) there are characters like <, >
. If I remove the conflicting character, the video uploads fine.
I can't seem to find it in documentation, but am I required to do some kind of sanitization? HTML escaping? Removal of everything thats ^A-Za-z0-9
? What about non-html usage of <
, like <3
? What about unicode characters? I'm confused.
EDIT:
To answer my question, here is a little hack I wrote to combat the issue of Google hating on >
, <
characters. I simply replace them with different UNICODE characters that look similar.
// < and > need to be stripped out, or the upload will throw 400 error
// https://developers.google.com/youtube/2.0/reference#youtube_data_api_tag_media:description
sanitize := func(val string) string {
replacements := map[string]string{
"<": "≺",
">": "≻",
}
for k, v := range replacements {
val = strings.Replace(val, k, v, -1)
}
return val
}