通过调用LiveBroadcasts: list接口可以从某个账号的所有频道获取信息。该接口是YouTube Data API的一部分,用于检索与指定频道关联的直播广播。以下是详细的步骤:
pip install google-api-python-client
from googleapiclient.discovery import build
from google.oauth2 import service_account
credentials = service_account.Credentials.from_service_account_file(
'path/to/your/credentials.json',
scopes=['https://www.googleapis.com/auth/youtube.readonly']
)
youtube = build('youtube', 'v3', credentials=credentials)
response = youtube.liveBroadcasts().list(
part='snippet',
mine=True
).execute()
for item in response['items']:
channel_id = item['snippet']['channelId']
channel_title = item['snippet']['title']
# 其他频道信息的处理
领取专属 10元无门槛券
手把手带您无忧上云