我注意到我HTTP 400
在尝试通过以下方式上传视频时遇到了很多问题:
https ://developers.google.com/youtube/v3/docs/videos/insert
我正在使用来自 Google 的 Go SDK: code.google.com/p/google-api-go-client
上传失败的共同点是,在视频片段数据(标题/描述)的某处,有类似<, >
. 如果我删除冲突字符,则视频上传正常。
我似乎无法在文档中找到它,但我需要进行某种消毒吗?HTML转义?删除一切^A-Za-z0-9
?非 html 使用<
, like怎么样<3
?unicode字符呢?我很困惑。
编辑:为了回答我的问题,这是我写的一个小技巧,以解决 Google 讨厌>
,<
字符的问题。我只是用看起来相似的不同 UNICODE 字符替换它们。
// < 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
}