Chris Ullyott
Chris Ullyott

Reputation: 27

Image thumbnails for a LiveBroadcast object

I can't seem to associate image thumbnails with a LiveBroadcast object as per the documentation when trying to create a live stream via the API.

For my application, I am using the following reference:

https://developers.google.com/youtube/v3/live/docs/liveBroadcasts#snippet.thumbnails

Here's an example of my payload sent to /liveBroadcasts:

array:3 [
  "snippet" => array:5 [
    "title" => "Test broadcast"
    "description" => "Test description",
    "thumbnails" => array:1 [
      "default" => array:3 [
        "url" => "my-image"
        "width" => 120
        "height" => 90
      ]
    ]
    "scheduledStartTime" => "2021-03-01T21:35:37.000000Z"
    "scheduledEndTime" => "2021-03-01T21:40:37.000000Z"
  ]
  "contentDetails" => array:2 [
    "enableAutoStart" => true
    "enableAutoStop" => true
  ]
  "status" => array:1 [
    "privacyStatus" => "public"
  ]
]

The URL to my-image of course is actually a working URL.

Must the images in thumbnails be previously uploaded to YouTube and hosted there instead? What else could I be missing?

Thank you!

Upvotes: 0

Views: 354

Answers (2)

Dave Bevan
Dave Bevan

Reputation: 886

Context: Using the PHP api.

After a successful INSERT, you can do the following:

$google_service_youtube->thumbnails->set('', [
  'videoId' => $insert_response->getid(),
  'data' => file_get_contents($imgfilename),
  'mimeType' => 'image/jpeg',  # or image/png
  'uploadType' => 'multipart',
]);

$imagefilename can be local or a url.

Upvotes: 0

stvar
stvar

Reputation: 6985

According to the official specs of the LiveBroadcasts.insert and LiveBroadcasts.update API endpoints, you're not allowed to set the respective live broadcast resource object's thumbnails property when invoking either of these endpoints:

Neither the request body of the former endpoint, nor the request body of the latter one has specified the property thumbnails among those accepted to be initialized or, respectively, modified.

For to update your live broadcast's thumbnails, you have to use the Thumbnails.set API endpoint instead, invoked appropriately with its request parameter videoId set to the ID of your broadcast.

For PHP (though it's not clear from your post what's your programming language/environment), look for the official Google sample code that is uploading thumbnails to YouTube using Thumbnails.set: upload_thumbnail.php.

Upvotes: 2

Related Questions