gpt4 book ai didi

go - YouTube 上传 v3 - 400 错误请求

转载 作者:数据小太阳 更新时间:2023-10-29 03:35:57 26 4
gpt4 key购买 nike

我注意到我得到了相当多的 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 用法如何? , 比如 <3 ? unicode字符呢?我很困惑。

编辑:为了回答我的问题,这里有一些我写的小技巧来解决谷歌讨厌 > 的问题。 , <人物。我只是用看起来相似的不同 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
}

最佳答案

一个问题是:

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.

由于它们是从 JSON 服务定义自动生成的,因此它们可能错过了合适的翻译。根据 API 文档,假设您使用的是 http 协议(protocol),视频信息将作为 JSON blob 发送。

Go 会为你转换特殊字符。所以 <> 等成为 JSON 有效的 unicode 转义序列。 Google 可能不喜欢转义序列,因此您可能想尝试发送文字字符。但我真的怀疑这是问题所在。

此外,由于您提到 <> youtube 不会让您输入 HTML,所以如果您正在这样做,或者看起来像 html 的东西,那可能是您出现无效字符错误的原因。您需要清理任何看起来像 html 的内容。

查看这篇文章:

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

这表明 golang 生成了 unicode 转义序列:

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

关于go - YouTube 上传 v3 - 400 错误请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24075229/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com