user14945611
user14945611

Reputation: 1

Is there a way to use the API to schedule a Live Stream Broadcast and add it to an existing playlist and specify the stream key?

I played around with the YouTube Data API and I was able to get a working poc of creating a scheduled live broadcast for my channel. However, in looking through the rest of the documentation I couldn't see that it was possible to add the stream to an existing playlist or specify the stream key. This is my poc code so far

# -*- coding: utf-8 -*-

import os
from datetime import datetime, timedelta

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]

def main():
    date = datetime.today()
    while date.weekday() != 6:
      date+=timedelta(1)

    date = date.isoformat() + "Z"
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "client_secret.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    request = youtube.liveBroadcasts().insert(
        part="snippet,contentDetails,status",
        access_token="REDACTED",
        body={
          "contentDetails": {
            "enableAutoStart": True,
            "enableAutoStop": True
          },
          "snippet": {
            "title": "Meeting",
            "scheduledStartTime": date,
            "thumbnails": {
               "default": {
                  "url": "https://50801759971_0dbb60afdf.jpg"
                }
             }
          },
          "status": {
           "privacyStatus": "unlisted",
           "selfDeclaredMadeForKids": False
          }
        }
    )
    response = request.execute()

Upvotes: 0

Views: 873

Answers (1)

Onisim Roman
Onisim Roman

Reputation: 11

Check out this site: https://developers.google.com/youtube/v3/docs/playlistItems/insert You have to specify the playlist ID (https://www.sociablekit.com/find-youtube-playlist-id/) and the broadcast ID (you can use the insert broadcast function that youtube api provides (https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/insert) to get the broadcast id for the video, for example broadcast_id = the function from the link)

Upvotes: 1

Related Questions