0
votes

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:

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'

I have tried:

-F 'image=@/Users/adviner/Projects/Prototypes/VendorAPI/source/YouTube/YouTube-BOS.jpg'\

In the documentation it says to use the following URL to POST the image:

https://www.googleapis.com/upload/youtube/v3/thumbnails/set

but when you view the sample it says to use:

https://youtube.googleapis.com/youtube/v3/thumbnails/set

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

{
  "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"
  }
}

When using the URL: https://youtube.googleapis.com/youtube/v3/thumbnails/set

{
  "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"
      }
    ]
  }
}

Any ideas on what I'm missing?

Thanks

2

2 Answers

2
votes

You'll have to use the URL that's on the spec document:

https://www.googleapis.com/upload/youtube/v3/thumbnails/set.

In my experience, the sample code page is not one hundred percent reliable (for example, the Videos.insert API endpoint suffers from the same issue).

You'll have to issue the following 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'

Notice that instead of the two -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.

0
votes

with postman http request :

[POST] https://www.googleapis.com/upload/youtube/v3/thumbnails/set?videoId={videoID}&uploadType=media

--headers:  Content-Type: image/jpeg
           Authorization: Bearer ....

send file as binary

enter image description here