YouTube Livestream API-提供标题时需要标题

时间:2018-07-04 21:40:30

标签: python-3.x youtube youtube-api python-requests youtube-livestreaming-api

我正在尝试使用Python Requests在Python 3中创建YouTube LiveBroadcast和LiveStream。到目前为止,我已经提出了以下建议:

# livebroadcast
data = {
    "kind": "youtube#liveBroadcast",
    "snippet": {
        "title" : str(channelName + " " + time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime())),
        "scheduledStartTime" : datetime.datetime.now().isoformat()
    },
    "status": {
        "privacyStatus": "private"
    },
    "contentDetails": {
        "monitorStream": {
            "enableMonitorStream": False
        }
    }
}
r = requests.post("https://www.googleapis.com/youtube/v3/liveBroadcasts", headers=headers, params={"part":"snippet,status,contentDetails"}, data=json.dumps(data))

# livestream
data = {
    "kind": "youtube#liveStream",
    "cdn": {
        "format": "1080p",
        "ingestionType": "rtmp"
    },
    "snippet": {
        "title": str(channelName + " " + time.strftime("%a, %d %b %Y %H:%M:%S %Z", time.localtime()))
    }
}
r = requests.post("https://www.googleapis.com/youtube/v3/liveStreams", headers=headers, params={"part":"snippet, cdn"}, data=json.dumps(data))

但我不断收到此错误:

{
    'error': {
        'code': 400,
        'errors': [{
            'reason': 'titleRequired',
            'extendedHelp': 'https://developers.google.com/youtube/v3/live/docs/liveBroadcasts/insert#request_body',
            'domain': 'youtube.liveBroadcast',
            'message': 'Title is required'
        }],
        'message': 'Title is required'
    }
}

我不明白为什么会收到此错误,因为我在两个请求正文中都指定了标题(或者至少这是我认为的做法)。任何帮助将不胜感激!

注意:出于各种原因,我无法使用Google's API Client Library for Python

0 个答案:

没有答案