GroupItems: insert
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
要求
HTTP 要求
POST https://youtubeanalytics.googleapis.com/v2/groupItems
授權
這項要求需要授權,且至少包含下列其中一個範圍 (進一步瞭解驗證和授權)。
範圍 |
https://www.googleapis.com/auth/yt-analytics.readonly |
查看 YouTube 內容的 YouTube 數據分析報表。這個範圍可存取使用者活動指標,例如觀看次數和評分次數。 |
https://www.googleapis.com/auth/yt-analytics-monetary.readonly |
查看 YouTube 內容的 YouTube 數據分析報表。這個範圍可存取使用者活動指標,以及預估收益和廣告成效指標。 |
https://www.googleapis.com/auth/youtube |
管理 YouTube 帳戶。在 YouTube Analytics API 中,頻道擁有者可使用這個範圍管理 YouTube 數據分析群組和群組項目。 |
https://www.googleapis.com/auth/youtubepartner |
查看及管理 YouTube 素材資源和相關內容。在 YouTube Analytics API 中,內容擁有者會使用這個範圍管理 YouTube 數據分析群組和群組項目。 |
參數
下表列出這項查詢支援的參數。列出的所有參數都是查詢參數。
參數 |
選用參數 |
onBehalfOfContentOwner |
string
這個參數只能用於適當的授權要求。注意:這個參數僅供擁有及管理多個 YouTube 頻道的 YouTube 內容合作夥伴使用。
onBehalfOfContentOwner 參數表示要求的授權憑證可識別代表參數值中指定內容擁有者的 YouTube 使用者。這項功能可讓內容擁有者驗證一次,即可存取所有影片和頻道資料,不必為每個頻道提供驗證憑證。使用者驗證的帳戶必須連結至指定的 YouTube 內容擁有者。 |
要求主體
在要求主體中提供 groupItem 資源。您必須為該資源指定下列屬性的值。
回應
如果成功插入項目,這個方法會在回應主體中傳回 groupItem 資源。
如果要求中指定的項目在發出要求前就已加入群組,此方法會傳回 HTTP 204
回應代碼 (No Content
)。
錯誤
下表列出 API 在回應對此方法的呼叫時可能傳回的錯誤訊息。詳情請參閱錯誤訊息說明文件。
錯誤類型 |
錯誤詳情 |
說明 |
forbidden (403) |
groupContainsMaximumNumberOfItems |
這個群組包含的項目數量已達上限。 |
試試看!
使用 APIs Explorer 呼叫這個 API,並查看 API 要求和回應。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThis API endpoint allows you to create a new group item within YouTube Analytics.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization is required using specific scopes, including options for both content owners and channel owners.\u003c/p\u003e\n"],["\u003cp\u003eThe request must include a groupItem resource in the body, specifying the \u003ccode\u003egroupId\u003c/code\u003e and \u003ccode\u003eresource.id\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eA successful insertion of the item returns a groupItem resource, and attempting to add a pre-existing item returns a \u003ccode\u003e204\u003c/code\u003e HTTP code.\u003c/p\u003e\n"],["\u003cp\u003eThe API will return a \u003ccode\u003e403\u003c/code\u003e error if the group has reached its maximum item capacity.\u003c/p\u003e\n"]]],["This documentation details the process of creating a group item via a `POST` request to the YouTube Analytics API (`/groupItems`). Authorization requires specific scopes, including `yt-analytics.readonly`, `yt-analytics-monetary.readonly`, `youtube`, or `youtubepartner`. The request body must include a `groupItem` resource, specifying `groupId` and `resource.id`. Content owners can use `onBehalfOfContentOwner` to authenticate for multiple channels. Successful creation returns the `groupItem` resource; a duplicate returns a `204` status. A `403` error occurs when the maximum number of items is reached.\n"],null,["# GroupItems: insert\n\nCreates a group item.\n\nRequest\n-------\n\n### HTTP request\n\n```\nPOST https://youtubeanalytics.googleapis.com/v2/groupItems\n```\n\n### Authorization\n\nThis request requires authorization with at least one of the following scopes ([read more about authentication and authorization](/youtube/analytics/authentication)).\n\n| Scopes ||\n|----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| https://www.googleapis.com/auth/yt-analytics.readonly | View YouTube Analytics reports for your YouTube content. This scope provides access to user activity metrics, like view counts and rating counts. |\n| https://www.googleapis.com/auth/yt-analytics-monetary.readonly | View YouTube Analytics monetary reports for your YouTube content. This scope provides access to user activity metrics and to estimated revenue and ad performance metrics. |\n| https://www.googleapis.com/auth/youtube | Manage your YouTube account. In the YouTube Analytics API, channel owners use this scope to manage YouTube Analytics groups and group items. |\n| https://www.googleapis.com/auth/youtubepartner | View and manage YouTube assets and associated content on YouTube. In the YouTube Analytics API, content owners use this scope to manage YouTube Analytics groups and group items. |\n\n### Parameters\n\nThe table below lists the parameters that this query supports. All of the parameters listed are query parameters.\n\n| Parameters ||\n|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| **Optional parameters** |||\n| `onBehalfOfContentOwner` | `string` This parameter can only be used in a properly [authorized request](/youtube/analytics/authentication). **Note:** This parameter is intended exclusively for YouTube content partners that own and manage many different YouTube channels. The **onBehalfOfContentOwner** parameter indicates that the request's authorization credentials identify a YouTube user who is acting on behalf of the content owner specified in the parameter value. 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 account that the user authenticates with must be linked to the specified YouTube content owner. |\n\n### Request body\n\nProvide a [groupItem resource](/youtube/analytics/reference/groupItems#resource) in the request body.\nFor that resource, you must specify a value for the following properties.\n\n\u003cbr /\u003e\n\n- `groupId`\n- `resource.id`\n\n\u003cbr /\u003e\n\nResponse\n--------\n\nIf the item is successfully inserted, this method returns a [groupItem resource](/youtube/analytics/reference/groupItems#resource) in the response body.\n\nIf the item specified in the request had already been included in the group before the request was made, this method returns an HTTP `204` response code (`No Content`).\n\nErrors\n------\n\nThe table below identifies error messages that the API could return in response to a call to this method. Please see the [error message](/youtube/analytics/reference/errors) documentation for more detail.\n\n| Error type | Error detail | Description |\n|-------------------|-------------------------------------|-----------------------------------------------------------------|\n| `forbidden (403)` | `groupContainsMaximumNumberOfItems` | The group already contains the maximum allowed number of items. |\n\nTry it!\n-------\n\nUse the APIs Explorer to call this API and see the API request and response."]]