LiveBroadcasts: update

更新广播。例如,您可以修改 liveBroadcast 资源的 contentDetails 对象中定义的广播设置。

常见使用场景

请求

HTTP 请求

PUT 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 属性包括 idsnippetcontentDetailsmonetizationDetailsstatus

请注意,对于参数值指定的任意部分,此方法会替换其所有可变属性的现有值。例如,广播的隐私状态在 status 部分定义。因此,如果您的请求要更新私享或不公开列出的广播,并且请求的 part 参数值包含 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 资源。 针对该资源:

  • 您必须为以下属性指定值:

    • id
    • snippet.scheduledStartTime
    • contentDetails.monitorStream.enableMonitorStream
    • contentDetails.monitorStream.broadcastStreamDelayMs

  • 您可以为以下属性设置值:

    • snippet.title
    • snippet.description
    • snippet.scheduledStartTime
    • snippet.scheduledEndTime
    • status.privacyStatus
    • contentDetails.monitorStream.enableMonitorStream
    • contentDetails.monitorStream.broadcastStreamDelayMs
    • contentDetails.enableAutoStart
    • contentDetails.enableAutoStop
    • contentDetails.enableClosedCaptions
    • contentDetails.enableDvr
    • contentDetails.enableEmbed
    • contentDetails.recordFromStart
    • monetizationDetails.cuepointSchedule.pauseAdsUntil

    如果您要提交更新请求,并且您的请求没有为已有值的属性指定值,则该属性的现有值将被删除。

响应

如果成功,此方法将在响应正文中返回 liveBroadcast 资源

错误数

下表列出了 API 在响应对此方法的调用时可能会返回的错误消息。如需了解详情,请参阅错误消息文档。

错误类型 错误详情 说明
forbidden (403) closedCaptionsTypeModificationNotAllowed 只有当广播处于 createdready 状态时,才能修改 contentDetails.closedCaptionsType 值。
forbidden (403) enabledModificationNotAllowed enabled 字段是只读的。
forbidden (403) scheduleStrategyModificationNotAllowed scheduleStrategy 字段是只读的。
forbidden (403) repeatIntervalSecsModificationNotAllowed repeatIntervalSecs 字段是只读的。
forbidden (403) pauseAdsUntilModificationNotAllowed 无法修改 pauseAdsUntil 字段。 出现此错误的可能原因如下:
  • monetizationDetails.cuepointSchedule.enabled 字段未设置为 true。此字段只能通过 YouTube 工作室设置。
  • 此直播未进行直播。
forbidden (403) enableAutoStartModificationNotAllowed 只有在视频流处于不活动状态且广播处于 createdready 状态时,才能修改 contentDetails.enableAutoStart 值。
forbidden (403) enableClosedCaptionsModificationNotAllowed 只有当广播的状态为 createdready 时,才能修改 contentDetails.enableClosedCaptions 值。
forbidden (403) enableDvrModificationNotAllowed 仅当广播的状态为 createdready 时,才能修改 contentDetails.enableDvr 值。
forbidden (403) enableMonitorStreamModificationNotAllowed 仅当广播的状态为 createdready 时,才能修改 contentDetails.monitorStream.enableMonitorStream 值。
forbidden (403) recordFromStartModificationNotAllowed 仅当广播的状态为 createdready 时,才能修改 contentDetails.recordFromStart 值。
insufficientPermissions insufficientLivePermissions 该请求无权更新指定的直播。如需了解详情,请参阅实现 OAuth2 身份验证
insufficientPermissions liveStreamingNotEnabled 对该请求进行授权的用户未启用在 YouTube 上直播实时视频的权限。用户可以访问 https://www.youtube.com/features 了解详情。
invalidValue (400) invalidAutoStart liveBroadcast 资源包含的 contentDetails.enableAutoStart 属性值无效。 您无法修改永久广播的 enableAutoStart 设置。
invalidValue (400) invalidAutoStop liveBroadcast 资源包含的 contentDetails.enableAutoStop 属性值无效。您无法修改持久性广播的 enableAutoStop 设置。
invalidValue (400) invalidDescription liveBroadcast 资源没有为 snippet.description 属性指定有效值。snippet.description 最多可包含 5,000 个字符。
invalidValue (400) invalidEmbedSetting liveBroadcast 资源包含的 contentDetails.enable_embed 属性值无效。你无法嵌入此广播。
invalidValue (400) invalidEnableClosedCaptions liveBroadcast 资源中,contentDetails.enableClosedCaptions 属性的值与 contentDetails.closedCaptionType 设置的值不兼容。请修改资源,使其仅包含这两个属性中的一个,然后重新提交请求。
invalidValue (400) invalidLatencyPreferenceOptions liveBroadcast 资源包含的 contentDetails.latencyPreference 属性值无效。 此延迟时间偏好设置并非支持所有设置。
invalidValue (400) invalidPauseAdsUntil liveBroadcast 资源包含的 monetizationDetails.cuepointSchedule.pauseAdsUntil 属性值无效。 出现此错误的可能原因如下:
  • monetizationDetails.cuepointSchedule.pauseAdsUntil 值未采用 ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) 格式指定。
  • monetizationDetails.cuepointSchedule.pauseAdsUntil 值不是将来的时间。
  • monetizationDetails.cuepointSchedule.pauseAdsUntil 值与当前时间相差超过 10 分钟。
invalidValue (400) invalidPrivacyStatus liveBroadcast 资源未指定有效的隐私权状态。请参阅有效的 privacyStatus
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 属性指定有效值。“snippet.title”的长度必须介于 1 到 100 个字符之间。
notFound (404) liveBroadcastNotFound liveBroadcast 资源中指定的 id 属性无法识别广播。
required (400) broadcastStreamDelayMsRequired liveBroadcast 资源未指定 contentDetails.monitorStream.broadcastStreamDelayMs 属性。
required (400) enableMonitorStreamRequired liveBroadcast 资源未指定 contentDetails.monitorStream.enableMonitorStream 属性。
required (400) idRequired liveBroadcast 资源必须包含 id 属性并为其指定一个值。
required (400) scheduledEndTimeRequired liveBroadcast 资源未指定 snippet.scheduledEndTime 属性。
required (400) scheduledStartTimeRequired liveBroadcast 资源未指定 snippet.scheduledStartTime 属性。

试试看!

使用 APIs Explorer 调用此 API 并查看 API 请求和响应。