使用curl将缩略图上传到Youtube API [英] Upload thumbnail to Youtube API using curl
问题描述
我正在将curl与YouTube API v3一起使用来创建广播,修改视频标题等,而没有任何问题.我的问题是,当我尝试使用文档
将缩略图添加到视频中来自Google.
这是我的示例,出于安全原因更改了密钥:
curl --request POST -v \" https://youtube.googleapis.com/youtube/v3/thumbnails/set \?videoId = RoZypUhZY04 \& uploadType = media \& key = mykey"\--header'授权:承载my_access_token'\--header'Content-Type:image/jpeg'\-F'file = @/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'\-F'filename = YouTube-BOS.jpg'
我尝试过:
-F'image = @/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'\
在文档中说使用以下URL来发布图像:
https://www.googleapis.com/upload/youtube/v3/thumbnails/set
但是当您查看示例时,它会说:
https://youtube.googleapis.com/youtube/v3/thumbnails/set
我都尝试过,似乎图像已正确上传,但是出现以下错误:
对于第一个网址: https://www.googleapis.com/上传/youtube/v3/缩略图/设置
{错误":{代码":400,消息":媒体类型'image/jpeg;不支持boundary = ------------------------ 136ebfc0c8146cb8'.",错误":[{消息":媒体类型'image/jpeg;不支持boundary = ------------------------ 136ebfc0c8146cb8'.","domain":"global",原因":"badRequest"}],状态":"INVALID_ARGUMENT";}}
使用网址时: https://youtube.googleapis.com/youtube/v3/缩略图/集
{错误":{代码":400," message":请求不包括图像内容.",错误":[{" message":请求不包括图像内容.",域":"youtube.thumbnail","reason":"mediaBodyRequired",位置":身体","locationType":其他"}]}}
关于我所缺少的东西有什么想法吗?
谢谢
您必须使用 请注意,上面的调用使用了一个 I'm using curl with YouTube API v3 to create a broadcast, modify video title, etc without any issues. My problem is when I try to add a thumbnail to a video using the docs from Google. Here is my sample with the keys changed for security reasons: I have tried: In the documentation it says to use the following URL to POST the image: but when you view the sample it says to use: I have tried both and it seems that the images are properly uploaded but I get the following errors: For the first URL: https://www.googleapis.com/upload/youtube/v3/thumbnails/set When using the URL: https://youtube.googleapis.com/youtube/v3/thumbnails/set Any ideas on what I'm missing? Thanks You'll have to use the URL that's on the spec document: In my experience, the sample code page is not one hundred percent reliable (for example, the You'll have to issue the following Notice that instead of the two 这篇关于使用curl将缩略图上传到Youtube API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! curl --request POST -v \" https://www.googleapis.com/upload/youtube/v3/thumbnails/set \?videoId = RoZypUhZY04 \& uploadType = media"\--header'授权:承载my_access_token'\--header'Content-Type:image/jpeg'\--data-binary'@/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'
-data-binary
选项,而不是两个 -F
选项( form 选项),其参数以 @
开头,以指示该参数的其余部分是文件名.curl --request POST -v \
"https://youtube.googleapis.com/youtube/v3/thumbnails/set\
?videoId=RoZypUhZY04\
&uploadType=media\
&key=mykey" \
--header 'Authorization: Bearer my_access_token' \
--header 'Content-Type: image/jpeg'\
-F 'file=@/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'\
-F 'filename=YouTube-BOS.jpg'
-F 'image=@/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'\
https://www.googleapis.com/upload/youtube/v3/thumbnails/set
https://youtube.googleapis.com/youtube/v3/thumbnails/set
{
"error": {
"code": 400,
"message": "Media type 'image/jpeg; boundary=------------------------136ebfc0c8146cb8' is not supported. ",
"errors": [
{
"message": "Media type 'image/jpeg; boundary=------------------------136ebfc0c8146cb8' is not supported. ",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
}
{
"error": {
"code": 400,
"message": "The request does not include the image content.",
"errors": [
{
"message": "The request does not include the image content.",
"domain": "youtube.thumbnail",
"reason": "mediaBodyRequired",
"location": "body",
"locationType": "other"
}
]
}
}
https://www.googleapis.com/upload/youtube/v3/thumbnails/set
.Videos.insert
API endpoint suffers from the same issue).curl
call:curl --request POST -v \
"https://www.googleapis.com/upload/youtube/v3/thumbnails/set\
?videoId=RoZypUhZY04\
&uploadType=media" \
--header 'Authorization: Bearer my_access_token' \
--header 'Content-Type: image/jpeg'\
--data-binary '@/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'
-F
options (form options), the call above uses one --data-binary
option, with its argument starting with @
to indicate that the rest of the argument is a file name.