-1

我注意到我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
}
4

1 回答 1

1

One issue is:

These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available "new style" Google APIs.

Announcement email: http://groups.google.com/group/golang-nuts/browse_thread/thread/6c7281450be9a21e

Status: Relative to the other Google API clients, this library is labeled alpha. Some advanced features may not work. Please file bugs if any problems are found.

Since they are auto generated from the JSON service definition, they may have missed the appropriate translation to go. From the API documentation, assuming you are using the http protocol, the video information is sent as a JSON blob.

Go will convert special characters for you. So <>, etc become JSON valid unicode escape sequences. Google may dislike escape sequences so you might want to try sending literal characters. But I really doubt that is the issue.

Also, since you mention <> youtube won't let you put in HTML so if that is what you are doing, or something that looks like html, that could be the reason for your invalid character error. You will need to sanitize anything that looks like html.

See this post:

https://groups.google.com/forum/#!topic/youtube-api-gdata/EcYPPlHjllY

This shows golang generates unicode escape sequences:

http://play.golang.org/p/hv2h7PA0tr

于 2014-06-09T20:51:44.897 回答