该 API 现在支持将直播标记为“面向儿童的内容”,
liveBroadcast
资源现在包含一个属性,用于标识该直播的“面向儿童的内容”状态。YouTube API 服务的服务条款和开发者政策也在 2020 年 1 月 10 日进行了更新。如需了解详情,请参阅 YouTube Live Streaming API 服务和 YouTube API 服务的服务条款的修订历史记录。创建广播。
常见使用场景
请求
HTTP 请求
POST https://www.googleapis.com/youtube/v3/liveBroadcasts
授权
此请求需要获得以下至少一个范围的授权(详细了解身份验证和授权)。
范围 |
---|
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
参数
下表列出了此查询支持的参数。列出的所有参数都是查询参数。
参数 | ||
---|---|---|
必需参数 | ||
part |
string part 参数在此操作中有两个目的。它用于标识写入操作将设置的属性以及 API 响应将包含的属性。您可以在参数值中添加的 part 属性为 id 、snippet 、contentDetails 和 status 。 |
|
可选参数 | ||
onBehalfOfContentOwner |
string 此参数只能在正确的授权请求中使用。注意:此参数专供 YouTube 内容合作伙伴使用。 onBehalfOfContentOwner 参数表示请求的授权凭据用于标识代表参数值中指定的内容所有者执行操作的 YouTube CMS 用户。此参数适用于拥有和管理许多不同 YouTube 频道的 YouTube 内容合作伙伴。内容所有者只需进行一次身份验证,即可访问自己所有的视频和频道数据,而无需为每个频道提供身份验证凭据。用户身份验证所用的 CMS 帐号必须与指定的 YouTube 内容所有者相关联。 |
|
onBehalfOfContentOwnerChannel |
string 此参数只能在正确的授权请求中使用。此参数只能在适当的授权请求中使用。注意:此参数仅适用于 YouTube 内容合作伙伴。 onBehalfOfContentOwnerChannel 参数用于指定要添加视频的频道的 YouTube 频道 ID。当请求为 onBehalfOfContentOwner 参数指定值时,必须提供此参数,并且该参数只能与该参数结合使用。此外,必须使用与 onBehalfOfContentOwner 参数指定的内容所有者相关联的 CMS 帐号对请求进行授权。最后,onBehalfOfContentOwnerChannel 参数值指定的频道必须与 onBehalfOfContentOwner 参数指定的内容所有者相关联。此参数适用于拥有和管理许多不同 YouTube 频道的 YouTube 内容合作伙伴。使用 Content ID,内容所有者只需进行一次身份验证,即可代表参数值中指定的频道执行操作,而无需为每个单独的频道提供身份验证凭据。 |
请求正文
在请求正文中提供 liveBroadcast 资源。对于相应资源:
-
您必须为以下属性指定值:
snippet.title
snippet.scheduledStartTime
status.privacyStatus
-
您可以为以下属性设置值:
snippet.title
snippet.description
snippet.scheduledStartTime
snippet.scheduledEndTime
status.privacyStatus
status.selfDeclaredMadeForKids
contentDetails.monitorStream.enableMonitorStream
contentDetails.monitorStream.broadcastStreamDelayMs
contentDetails.enableAutoStart
contentDetails.enableAutoStop
contentDetails.enableClosedCaptions
contentDetails.enableDvr
contentDetails.enableEmbed
contentDetails.recordFromStart
响应
如果成功,此方法将在响应正文中返回 liveBroadcast 资源。
错误
下表列出了该 API 为响应对此方法的调用可能返回的错误消息。如需了解详情,请参阅错误消息文档。
错误类型 | 错误详情 | 说明 |
---|---|---|
insufficientPermissions |
insufficientLivePermissions |
该请求未获得创建直播的授权。 |
insufficientPermissions |
livePermissionBlocked |
授权请求的用户目前无法在 YouTube 上直播视频。您可以在 https://www.youtube.com/features 的用户频道设置中找到解释用户无法直播视频的详细信息。 |
insufficientPermissions |
liveStreamingNotEnabled |
授权请求的用户无法在 YouTube 上直播视频。用户可以访问 https://www.youtube.com/features 查找更多信息。 |
invalidValue (400) |
invalidAutoStart |
liveBroadcast 资源的 contentDetails.enableAutoStart 属性值无效。
并非所有广播都支持此设置。 |
invalidValue (400) |
invalidAutoStop |
liveBroadcast 资源的 contentDetails.enableAutoStop 属性值无效。您不能修改永久性广播的 enableAutoStop 设置。 |
invalidValue (400) |
invalidDescription |
liveBroadcast 资源没有为 snippet.description 属性指定有效值。该属性值最多可包含 5000 个字符。 |
invalidValue (400) |
invalidEmbedSetting |
liveBroadcast 资源的 contentDetails.enable_embed 属性值无效。您不能嵌入此广播。 |
invalidValue (400) |
invalidLatencyPreferenceOptions |
liveBroadcast 资源的 contentDetails.latencyPreference 属性值无效。
此延迟偏好设置并不支持所有设置。
|
invalidValue (400) |
invalidPrivacyStatus |
liveBroadcast 资源的 status.privacy_status 属性值无效。 |
invalidValue (400) |
invalidProjection |
liveBroadcast 资源的 contentDetails.projection 属性值无效。无法将默认广播的投影设为 360 。 |
invalidValue (400) |
invalidScheduledEndTime |
liveBroadcast 资源的 snippet.scheduledEndTime 属性值无效。预定的结束时间必须晚于预定的开始时间。 |
invalidValue (400) |
invalidScheduledStartTime |
liveBroadcast 资源的 snippet.scheduledStartTime 属性值无效。预定的开始时间必须是将来的时间,并且足够接近当前时间,以便能够在当时可靠地安排广播。 |
invalidValue (400) |
invalidTitle |
liveBroadcast 资源没有为 snippet.title 属性指定有效值。属性值的长度必须介于 1 到 100 个字符之间。 |
limitExceeded |
userBroadcastsExceedLimit |
用户创建的直播或预定的直播过多,必须停止或删除。 |
rateLimitExceeded |
userRequestsExceedRateLimit |
用户在指定时间范围内发送的请求过多。 |
required (400) |
privacyStatusRequired |
liveBroadcast 资源必须指定隐私状态。请参阅有效的 privacyStatus 值。 |
required (400) |
scheduledEndTimeRequired |
liveBroadcast 资源必须指定 snippet.scheduledEndTime 属性。 |
required (400) |
scheduledStartTimeRequired |
liveBroadcast 资源必须指定 snippet.scheduledStartTime 属性。 |
required (400) |
titleRequired |
liveBroadcast 资源必须指定 snippet.title 属性。 |
试试看!
使用 APIs Explorer 调用此 API,并查看 API 请求和响应。