该 API 现在支持将您的 直播
广播 标记为“面向儿童”,并且
liveBroadcast 资源现在包含一个
属性,用于标识该直播的“面向儿童”状态。YouTube API
服务的《服务条款》和《开发者政策》也于 2020 年 1 月 10 日进行了更新。如需了解详情,请参阅
YouTube 直播 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 |
stringpart 参数在此操作中具有两个用途。它用于标识写入操作将设置的属性以及 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 内容合作伙伴。它允许内容所有者进行一次身份验证,即可代表参数值中指定的频道执行操作,而无需为每个频道提供身份验证凭据。 |
|
请求正文
在请求正文中提供 liveBroadcast 资源。 对于该资源:
-
您必须为以下属性指定值:
snippet.titlesnippet.scheduledStartTimestatus.privacyStatus
-
您可以为以下属性设置值:
snippet.titlesnippet.descriptionsnippet.categoryIdsnippet.scheduledStartTimesnippet.scheduledEndTimestatus.privacyStatusstatus.selfDeclaredMadeForKidscontentDetails.monitorStream.enableMonitorStreamcontentDetails.monitorStream.broadcastStreamDelayMscontentDetails.enableAutoStartcontentDetails.enableAutoStopcontentDetails.enableClosedCaptionscontentDetails.enableDvrcontentDetails.enableEmbedcontentDetails.recordFromStartcontentDetails.availabilityConfig
响应
如果成功,此方法会在响应正文中返回 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 请求和响应。