我尝试将一些视频上传到 youtube。在堆栈的某处,它归结为 http.Client
。这部分以某种方式表现得很奇怪。
请求和所有内容都在 youtube 包中创建。
在完成我的请求后,它最终失败了:
Error uploading video: Post https://www.googleapis.com/upload/youtube/v3/videos?alt=json&part=snippet%2Cstatus&uploadType=multipart: Post : unsupported protocol scheme ""
我稍微调试了库并打印了 URL.Scheme
内容。作为一个字符串,结果是 https
并且在 []byte
[104 116 116 112 115]
https://golang.org/src/net/http/transport.go第288行是抛出错误的位置。
https://godoc.org/google.golang.org/api/youtube/v3我使用的图书馆
我准备/上传视频的代码:
//create video struct which holds info about the video
video := &yt3.Video{
//TODO: set all required video info
}
//create the insert call
insertCall := service.Videos.Insert("snippet,status", video)
//attach media data to the call
insertCall = insertCall.Media(tmp, googleapi.ChunkSize(1*1024*1024)) //1MB chunk
video, err = insertCall.Do()
if err != nil {
log.Printf("Error uploading video: %v", err)
return
//return errgo.Notef(err, "Failed to upload to youtube")
}
所以我不知道为什么模式检查失败。
最佳答案
好的,我想通了。问题不在于调用 YouTube 本身。
库尝试在后台刷新 token ,但 TokenURL
有问题。
确保有一个有效的 URL 解决了这个问题。
一个更好的错误信息会有很大帮助,但是......
关于http.Client 拒绝使用 >unsupported protocol scheme ""< 即使已设置的请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37548915/