有没有办法使用API来安排直播,并将其添加到现有播放列表中并指定流密钥



我使用了YouTube Data API,我能够获得为我的频道创建预定直播的工作机会。然而,在浏览其余文档时,我看不出是否可以将流添加到现有播放列表或指定流密钥。这是迄今为止我的poc代码

# -*- 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()

查看此网站:https://developers.google.com/youtube/v3/docs/playlistItems/insert您必须指定播放列表ID(https://www.sociablekit.com/find-youtube-playlist-id/)和广播ID(您可以使用youtubeapi提供的插入广播功能(https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/insert)获取视频的广播id,例如broadcast_id=链接中的函数(

最新更新