我們正在更新 Data API,以符合 YouTube 計算 Shorts 觀看次數的方式。
瞭解詳情
Captions: update
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
更新字幕軌。更新字幕軌時,您可以變更曲目的草稿狀態和/或上傳該曲目的新字幕檔。
這個方法支援媒體上傳功能。上傳的檔案必須符合下列條件:
- 檔案大小上限:100 MB
- 接受的媒體 MIME 類型:
text/xml
、application/octet-stream
、*/*
配額影響:呼叫這個方法的配額費用為 450 個單位。
常見用途
要求
HTTP 要求
PUT https://www.googleapis.com/upload/youtube/v3/captions
授權
這項要求需要至少下列其中一個範圍的授權 (進一步瞭解驗證和授權)。
範圍 |
https://www.googleapis.com/auth/youtube.force-ssl |
https://www.googleapis.com/auth/youtubepartner |
參數
下表列出此查詢支援的參數。這裡列出的參數全都是查詢參數。
參數 |
必要參數 |
part |
string
在這項作業中,part 參數有兩個用途。它會識別寫入作業設定的屬性,以及 API 回應將包含的屬性。如要更新曲目的草稿狀態,請將屬性值設為 snippet 。否則,請將屬性值設為 id 。
以下清單包含您可以加入參數值的 part 名稱:
|
選用參數 |
onBehalfOfContentOwner |
string
這個參數只能在正確的授權要求中使用。注意:這個參數僅適用於 YouTube 內容合作夥伴。
onBehalfOfContentOwner 參數代表透過要求的授權憑證,代表 YouTube CMS 使用者,代表在參數值中指定的內容擁有者擔任代理人。這個參數適用於擁有及管理多個不同 YouTube 頻道的 YouTube 內容合作夥伴。內容擁有者只要通過一次驗證,即可存取所有影片和頻道資料,不必分別提供各個頻道的驗證憑證。使用者用來驗證的實際 CMS 帳戶,必須連結至指定的 YouTube 內容擁有者。 |
sync |
boolean
這個參數已淘汰。
注意:如果要求包含更新後的字幕檔,API 伺服器只會處理參數值。
sync 參數會指出 YouTube 是否應將字幕檔案與影片音軌保持同步。如果將值設為「true 」,YouTube 就會自動同步處理字幕軌和音軌。 |
回應
如果成功的話,這個方法會在回應內文中傳回字幕資源。
錯誤
下表列出 API 回應此方法時可能傳回的錯誤訊息。詳情請參閱錯誤訊息的說明文件。
錯誤類型 |
錯誤詳細資料 |
說明 |
badRequest (400) |
contentRequired |
要求未上傳更新的字幕檔案。如果 sync 參數設為 true ,就必須提供實際的曲目內容。 |
forbidden (403) |
forbidden |
請注意,與要求相關聯的權限不足以更新字幕軌。要求可能未獲適當授權。 |
notFound (404) |
captionNotFound |
找不到指定的字幕軌。檢查要求的 id 屬性值,確認該值正確無誤。 |
試試看!
使用 APIs Explorer 呼叫這個 API 並查看 API 要求和回應。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2024-04-26 (世界標準時間)。
[null,null,["上次更新時間:2024-04-26 (世界標準時間)。"],[],[],null,["# Captions: update\n\nUpdates a caption track. When updating a caption track, you can change the track's [draft status](/youtube/v3/docs/captions#snippet.isDraft), upload a new caption file for the track, or both.\n\nThis method supports media upload. Uploaded files must conform to these constraints:\n\n- **Maximum file size:** 100MB\n- **Accepted Media MIME types:** `text/xml`, `application/octet-stream`, `*/*`\n\n**Quota impact:** A call to this method has a [quota cost](/youtube/v3/getting-started#quota) of 450 units.\n\nCommon use cases\n----------------\n\nThe list below shows common use cases for this method. Hover over a use case to see its description, or click on a use case to load sample parameter values in the APIs Explorer. You can open the [fullscreen APIs Explorer](#) to see code samples that dynamically update to reflect the parameter values entered in the Explorer.\n\nThe table below shows common use cases for this method. You can click on a use case name to load sample parameter values in the APIs Explorer. Or you can see code samples for a use case in the fullscreen APIs Explorer by clicking on the code icon below a use case name. In the fullscreen UI, you can update parameter and property values and the code samples will dynamically update to reflect the values you enter. \nThis method has one common use case, which is described below. The buttons below the description populate the APIs Explorer with sample values or open the fullscreen APIs Explorer to show code samples that use those values. The code samples also dynamically update if you change the values.\n\n\u003cbr /\u003e\n\nRequest\n-------\n\n### HTTP request\n\n```\nPUT https://www.googleapis.com/upload/youtube/v3/captions\n```\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes ([read more about authentication and authorization](/youtube/v3/guides/authentication)).\n\n| Scope |\n|-----------------------------------------------------|\n| `https://www.googleapis.com/auth/youtube.force-ssl` |\n| `https://www.googleapis.com/auth/youtubepartner` |\n\n### Parameters\n\nThe following table lists the parameters that this query supports. All of the parameters listed are query parameters.\n\n| Parameters ||\n|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| **Required parameters** |||\n| `part` | `string` The **part** parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include. Set the property value to `snippet` if you are updating the track's [draft status](/youtube/v3/docs/captions#snippet.isDraft). Otherwise, set the property value to `id`. The following list contains the `part` names that you can include in the parameter value: - `id` - `snippet` |\n| **Optional parameters** |||\n| `onBehalfOfContentOwner` | `string` This parameter can only be used in a properly [authorized request](/youtube/v3/guides/authentication). **Note:** This parameter is intended exclusively for YouTube content partners. The **onBehalfOfContentOwner** parameter indicates that the request's authorization credentials identify a YouTube CMS user who is acting on behalf of the content owner specified in the parameter value. This parameter is intended for YouTube content partners that own and manage many different YouTube channels. It allows content owners to authenticate once and get access to all their video and channel data, without having to provide authentication credentials for each individual channel. The actual CMS account that the user authenticates with must be linked to the specified YouTube content owner. |\n| `sync` | `boolean` This parameter has been deprecated. **Note:** The API server only processes the parameter value if the request contains an updated caption file. The **sync** parameter indicates whether YouTube should automatically synchronize the caption file with the audio track of the video. If you set the value to `true`, YouTube will automatically synchronize the caption track with the audio track. |\n\n### Request body\n\nProvide a [caption resource](/youtube/v3/docs/captions#resource) in the request body.\nFor that resource:\n\n- You must specify a value for these properties:\n\n \u003cbr /\u003e\n\n - `id`\n\n \u003cbr /\u003e\n\n- You can set values for these properties:\n\n \u003cbr /\u003e\n\n - `snippet.isDraft`\n\n \u003cbr /\u003e\n\n If you are submitting an update request, and your request does not specify a value for a property that already has a value, the property's existing value will be deleted.\n\nResponse\n--------\n\nIf successful, this method returns a [caption resource](/youtube/v3/docs/captions#resource) in the response body.\n\nErrors\n------\n\nThe following table identifies error messages that the API could return in response to a call to this method. Please see the [error message](/youtube/v3/docs/errors) documentation for more detail.\n\n| Error type | Error detail | Description |\n|--------------------|-------------------|-------------------------------------------------------------------------------------------------------------------------------------------|\n| `badRequest (400)` | `contentRequired` | The request did not upload an updated caption file. The actual track contents are required if the `sync` parameter is set to `true`. |\n| `forbidden (403)` | `forbidden` | The permissions associated with the request are not sufficient to update the caption track. The request might not be properly authorized. |\n| `notFound (404)` | `captionNotFound` | The specified caption track could not be found. Check the value of the request's `id` property to ensure that it is correct. |\n\nTry it!\n-------\n\nUse the APIs Explorer to call this API and see the API request and response."]]