我将 Node.js 用作后端技术,并将googleapis library用作简单的YouTube-api集成工具。
const {
google: {
auth: { OAuth2 },
youtube,
},
} = GoogleApis;
const oauth2Client = new OAuth2(tokenId, secretKey, redirectUrl);
const youTube = youtube({ version: 'v3', auth: oauth2Client });
流量:
1)直播创建。
youTube.liveBroadcasts.insert({
part: 'id,snippet,status,contentDetails',
requestBody: {
snippet,
contentDetails: { monitorStream: { enableMonitorStream: false } },
status: { privacyStatus: 'public' },
},
}),
代码段包含ScheduledStartTime,标题和说明。
2)实时流创建。
youTube.liveStreams.insert({
part: 'id,snippet,cdn',
requestBody: {
snippet,
cdn: {
ingestionType: 'rtmp',
frameRate: 'variable',
resolution: 'variable',
},
},
}),
代码段包含标题和说明。
3)将liveBroadcast绑定到liveStream
youTube.liveBroadcasts.bind({
part: 'id',
id,
streamId,
}),
此时,liveBroadcast状态为“就绪”,liveStream状态-为“就绪”。
4)开始使用liveStream rtmp键向YouTube广播视频流。
5)。等待15秒。
此时,liveBroadcast状态为“就绪”,liveStream状态-为“活动”。
6)使liveBroadcast状态从“就绪”转换为“实时”
youTube.liveBroadcasts.transition({
part: 'id',
id,
broadcastStatus: 'live',
}),
此时,liveBroadcast状态为“实时”,liveStream状态-为“活动”。
到目前为止,一切都按预期进行。
7)使liveBroadcast状态从“实时”转换为“完成”。
youTube.liveBroadcasts.transition({
part: 'id',
id,
broadcastStatus: 'complete',
}),
这里发生了黑魔法:YouTube-api
返回404 liveBroadcastNotFound
。
liveBroadcast似乎消失了。 几天后的几天,此liveBroadcast出现(变为可用)。
作为响应,我得到下一个错误响应(在JSON formatter下面粘贴JSON):
{“ response”:{“ config”:{“ url”:“ https://www.googleapis.com/youtube/v3/liveBroadcasts/transition?part=id&id= $ {liveBroadcastIdReplacedHere}&broadcastStatus = complete”,“ method”:“ POST”,“ headers”:{“ Accept-Encoding “:” gzip“,”用户代理“:” google-api-nodejs-client / 2.0.4 (gzip)“,”授权“:”承载者 $ {jwtTokenReplacedHere}“,” Accept“:” application / json“},” params“:{” part“:” id“,” id“:” $ {liveBroadcastIdReplacedHere}“,” broadcastStatus“:” complete“}, “ retry”:true,“ responseType”:“ json”,“ retryConfig”:{“ currentRetryAttempt”:0,“ retry”:3,“ retryDelay”:100,“ httpMethodsToRetry”:[“ GET”,“ HEAD”, “ PUT”,“ OPTIONS”,“ DELETE”],“ noResponseRetries”:2,“ statusCodesToRetry”:[[100,199],[429,429],[500,599]]}},“数据”:{“错误”:{“错误“:[{”域“:” youtube.liveBroadcast“,”原因“:” liveBroadcastNotFound“,”邮件“:”广播 找不到]“]”,“代码”:404,“消息”:“未广播 找到“}},”标题“:{” alt-svc“:” quic = \“:443 \”; ma = 2592000; v = \“ 46,43 \”,h3-Q048 = \“:443 \”; ma = 2592000,h3-Q046 = \“:443 \”; ma = 2592000,h3-Q043 = \“:443 \”; ma = 2592000“,”缓存控制“:”私有, max-age = 0“,” connection“:” close“,” content-encoding“:” gzip“,” content-type“:” application / json; charset = UTF-8“,” date“:” Wed,02 Oct 2019 13:10:02 GMT“,” expires“:” Wed, 2019年10月02日13:10:02 GMT”,“服务器”:“ GSE”,“传输编码”:“分块”,“变化”:“来源, X-Origin“,” x-content-type-options“:” nosniff“,” x-frame-options“:” SAMEORIGIN“,” x-xss-protection“:” 1; mode = block“},” status“:404,” statusText“:”不 找到“},” config“:{” url“:” https://www.googleapis.com/youtube/v3/liveBroadcasts/transition?part=id&id= $ {liveBroadcastIdReplacedHere}&broadcastStatus = complete“,” method“:” POST“,” headers“:{” Accept-Encoding“:” gzip“ ,“ User-Agent”:“ google-api-nodejs-client / 2.0.4 (gzip)“,”授权“:”承载者 $ {jwtTokenReplacedHere}“,” Accept“:” application / json“},” params“:{” part“:” id“,” id“:” $ {liveBroadcastIdReplacedHere}“,” broadcastStatus“:” complete“}, “ retry”:true,“ responseType”:“ json”,“ retryConfig”:{“ currentRetryAttempt”:0,“ retry”:3,“ retryDelay”:100,“ httpMethodsToRetry”:[“ GET”,“ HEAD”, “ PUT”,“ OPTIONS”,“ DELETE”],“ noResponseRetries”:2,“ statusCodesToRetry”:[[100,199],[429,429],[500,599]]}},“代码”:404,“错误”:[ {“ domain”:“ youtube.liveBroadcast”,“ reason”:“ liveBroadcastNotFound”,“ message”:“ Broadcast 找不到“}]}
我使用YouTube UI for developers遇到相同的错误