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 |
stringpart 參數在這項作業中有兩個用途。這項參數會識別寫入作業設定的屬性,以及 API 回應包含的屬性。您可以在參數值中加入的 part 屬性包括 id、snippet、contentDetails 和 status。 |
|
| 選用參數 | ||
onBehalfOfContentOwner |
string這個參數只能用於授權要求。注意:這個參數僅供 YouTube 內容合作夥伴使用。 onBehalfOfContentOwner 參數表示要求的授權憑證會識別 YouTube CMS 使用者,該使用者代表參數值中指定的內容擁有者。這個參數適用於擁有及管理多個不同 YouTube 頻道的 YouTube 內容合作夥伴。內容擁有者只需驗證一次,即可存取所有影片和頻道資料,不必為每個頻道提供驗證憑證。使用者驗證的 CMS 帳戶必須連結至指定的 YouTube 內容擁有者。 |
|
onBehalfOfContentOwnerChannel |
string這個參數只能用於授權要求。這項參數只能用於已授權的要求。注意:這個參數僅適用於 YouTube 內容合作夥伴。 onBehalfOfContentOwnerChannel 參數會指定影片要加入的 YouTube 頻道 ID。如果要求指定 onBehalfOfContentOwner 參數的值,就必須提供這項參數,且只能與該參數搭配使用。此外,要求必須使用 CMS 帳戶授權,該帳戶必須連結至 onBehalfOfContentOwner 參數指定的內容擁有者。最後,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 屬性指定有效值。屬性值最多可包含 5,000 個字元。 |
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 要求和回應。