更新广播。例如,您可以修改 liveBroadcast 资源的 contentDetails 对象中定义的广播设置。
常见使用场景
请求
HTTP 请求
PUT https://www.googleapis.com/youtube/v3/liveBroadcasts
授权
此请求需要获得以下至少一个范围的授权。如需详细了解身份验证和授权,请参阅实现 OAuth 2.0 授权。
| 范围 | 
|---|
https://www.googleapis.com/auth/youtube | 
https://www.googleapis.com/auth/youtube.force-ssl | 
参数
下表列出了此查询支持的参数。列出的所有参数都是查询参数。
| 参数 | ||
|---|---|---|
| 必需参数 | ||
part | 
      string在本操作中, part 参数有两个用途。它用于标识写入操作将设置的属性以及 API 响应将包含的属性。您可以在参数值中包含的 part 属性包括 id、snippet、contentDetails、monetizationDetails 和 status。请注意,此方法会替换参数值指定的任何部分中包含的所有可变属性的现有值。例如,广播的隐私权状态在 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 资源。 对于该资源:
- 
    
您必须为以下属性指定值:
idsnippet.scheduledStartTimecontentDetails.monitorStream.enableMonitorStreamcontentDetails.monitorStream.broadcastStreamDelayMs
 - 
    
您可以为以下属性设置值:
snippet.titlesnippet.descriptionsnippet.scheduledStartTimesnippet.scheduledEndTimestatus.privacyStatuscontentDetails.monitorStream.enableMonitorStreamcontentDetails.monitorStream.broadcastStreamDelayMscontentDetails.enableAutoStartcontentDetails.enableAutoStopcontentDetails.enableClosedCaptionscontentDetails.enableDvrcontentDetails.enableEmbedcontentDetails.recordFromStartmonetizationDetails.cuepointSchedule.pauseAdsUntil
如果您要提交更新请求,而您的请求没有为已具有值的媒体资源指定值,则该属性的现有值将被删除。
 
响应
如果成功,此方法将在响应正文中返回 liveBroadcast 资源。
错误
下表列出了 API 在响应此方法调用时可能会返回的错误消息。如需了解详情,请参阅错误消息。
| 错误类型 | 错误详情 | 说明 | 
|---|---|---|
forbidden (403) | 
      closedCaptionsTypeModificationNotAllowed | 
      只有当广播处于 created 或 ready 状态时,才能修改 contentDetails.closedCaptionsType 值。 | 
    
forbidden (403) | 
      enabledModificationNotAllowed | 
      enabled 字段为只读字段。 | 
    
forbidden (403) | 
      scheduleStrategyModificationNotAllowed | 
      scheduleStrategy 字段为只读字段。 | 
    
forbidden (403) | 
      repeatIntervalSecsModificationNotAllowed | 
      repeatIntervalSecs 字段为只读字段。 | 
    
forbidden (403) | 
      pauseAdsUntilModificationNotAllowed | 
      pauseAdsUntil 字段无法修改。出现此错误的原因如下:
        
  | 
    
forbidden (403) | 
      enableAutoStartModificationNotAllowed | 
      只有在数据流处于非活动状态且广播处于 created 或 ready 状态时,才能修改 contentDetails.enableAutoStart 值。 | 
    
forbidden (403) | 
      enableClosedCaptionsModificationNotAllowed | 
      只有在广播的状态为 created 或 ready 时,才能修改 contentDetails.enableClosedCaptions 值。 | 
    
forbidden (403) | 
      enableDvrModificationNotAllowed | 
      仅当广播的状态为 created 或 ready 时,才能修改 contentDetails. 值。 | 
    
forbidden (403) | 
      enableMonitorStreamModificationNotAllowed | 
      仅当广播的状态为 created 或 ready 时,才能修改 contentDetails. 值。 | 
    
forbidden (403) | 
      recordFromStartModificationNotAllowed | 
      仅当广播的状态为 created 或 ready 时,才能修改 contentDetails. 值。 | 
    
insufficientPermissions | 
      insufficientLivePermissions | 
      该请求无权更新指定的直播。如需了解详情,请参阅实现 OAuth2 身份验证。 | 
insufficientPermissions | 
      liveStreamingNotEnabled | 
      授权该请求的用户未获准在 YouTube 上直播视频。用户可以访问 https://www.youtube.com/features 了解详情。 | 
invalidValue (400) | 
      invalidAutoStart | 
      直播资源包含 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 | 
      在直播资源中,contentDetails.enableClosedCaptions 属性的值与 contentDetails.closedCaptionType 设置的值不兼容。请修改资源,使其仅包含这两项属性中的一项,然后重新提交请求。 | 
    
invalidValue (400) | 
      invalidLatencyPreferenceOptions | 
      liveBroadcast 资源的 contentDetails.latencyPreference 属性值无效。
此延迟时间偏好设置不支持所有设置。
         | 
    
invalidValue (400) | 
      invalidPauseAdsUntil | 
      直播资源包含 monetizationDetails.cuepointSchedule.pauseAdsUntil 属性的无效值。
        出现此错误的原因如下:
        
  | 
    
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 | 
      直播资源中指定的 id 属性未标识直播。 | 
    
required (400) | 
      broadcastStreamDelayMsRequired | 
      liveBroadcast 资源未指定 contentDetails. 属性。 | 
    
required (400) | 
      enableMonitorStreamRequired | 
      liveBroadcast 资源未指定 contentDetails. 属性。 | 
    
required (400) | 
      idRequired | 
      liveBroadcast 资源必须包含 id 属性并为其指定值。 | 
    
required (400) | 
      scheduledEndTimeRequired | 
      liveBroadcast 资源未指定 snippet.scheduledEndTime 属性。 | 
    
required (400) | 
      scheduledStartTimeRequired | 
      liveBroadcast 资源未指定 snippet.scheduledStartTime 属性。 | 
    
试试看!
使用 APIs Explorer 调用此 API,并查看 API 请求和响应。