Chúng tôi đang cập nhật Data API để phù hợp với cách YouTube tính số lượt xem video ngắn.
Tìm hiểu thêm
Subscriptions: insert
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Thêm một gói thuê bao cho kênh của người dùng đã xác thực.
Tác động đến hạn mức: Lệnh gọi đến phương thức này có chi phí hạn mức là 50 đơn vị.
Các trường hợp sử dụng phổ biến
Yêu cầu
Yêu cầu HTTP
POST https://www.googleapis.com/youtube/v3/subscriptions
Ủy quyền
Yêu cầu này cần được uỷ quyền với ít nhất một trong các phạm vi sau (đọc thêm về quy trình xác thực và uỷ quyền).
Phạm vi |
https://www.googleapis.com/auth/youtubepartner |
https://www.googleapis.com/auth/youtube |
https://www.googleapis.com/auth/youtube.force-ssl |
Tham số
Bảng sau đây liệt kê các tham số mà truy vấn này hỗ trợ. Tất cả tham số được liệt kê đều là tham số truy vấn.
Tham số |
Tham số bắt buộc |
part |
string
Tham số part phục vụ hai mục đích trong thao tác này. Thuộc tính này xác định các thuộc tính mà thao tác ghi sẽ đặt, cũng như các thuộc tính mà phản hồi API sẽ đưa vào.
Danh sách sau đây chứa các tên part mà bạn có thể đưa vào giá trị tham số:
contentDetails
id
snippet
subscriberSnippet
|
Nội dung yêu cầu
Cung cấp tài nguyên gói thuê bao trong nội dung yêu cầu.
Đối với tài nguyên đó:
Lỗi
Bảng sau đây xác định các thông báo lỗi mà API có thể trả về để phản hồi lệnh gọi đến phương thức này. Vui lòng xem tài liệu về thông báo lỗi để biết thêm chi tiết.
Loại lỗi |
Chi tiết lỗi |
Nội dung mô tả |
badRequest (400) |
subscriptionDuplicate |
Gói thuê bao mà bạn đang cố gắng tạo đã tồn tại. |
badRequest (400) |
subscriptionForbidden |
Bạn đã đạt đến số lượng gói thuê bao tối đa. |
badRequest (400) |
subscriptionForbidden |
Bạn không thể đăng ký kênh của mình. |
badRequest (400) |
subscriptionForbidden |
Quá nhiều gói thuê bao gần đây. Vui lòng thử lại sau vài giờ. |
forbidden (403) |
subscriptionForbidden |
Yêu cầu không được xác thực chính xác hoặc không được hỗ trợ cho kênh này. |
notFound (404) |
publisherNotFound |
Không thể tìm thấy tài nguyên được chỉ định bởi thuộc tính snippet.resourceId của yêu cầu. |
notFound (404) |
subscriberNotFound |
Không thể tìm thấy người đăng ký được xác định có yêu cầu. |
required (400) |
publisherRequired |
Tài nguyên gói thuê bao được chỉ định trong yêu cầu phải sử dụng thuộc tính snippet.resourceId để xác định kênh đang đăng ký. |
Hãy dùng thử!
Dùng APIs Explorer để gọi API này cũng như xem yêu cầu và phản hồi của API.
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2024-04-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2024-04-26 UTC."],[],[],null,["# Subscriptions: insert\n\nAdds a subscription for the authenticated user's channel.\n\n**Quota impact:** A call to this method has a [quota cost](/youtube/v3/getting-started#quota) of 50 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```\nPOST https://www.googleapis.com/youtube/v3/subscriptions\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/youtubepartner` |\n| `https://www.googleapis.com/auth/youtube` |\n| `https://www.googleapis.com/auth/youtube.force-ssl` |\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. The following list contains the `part` names that you can include in the parameter value: - `contentDetails` - `id` - `snippet` - `subscriberSnippet` |\n\n### Request body\n\nProvide a [subscription resource](/youtube/v3/docs/subscriptions#resource) in the request body.\nFor that resource:\n\n- You must specify a value for these properties:\n\n \u003cbr /\u003e\n\n - `snippet.resourceId`\n\n \u003cbr /\u003e\n\n- You can set values for these properties:\n\n \u003cbr /\u003e\n\n - `snippet.resourceId`\n\n \u003cbr /\u003e\n\nResponse\n--------\n\nIf successful, this method returns a [subscription resource](/youtube/v3/docs/subscriptions#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)` | `subscriptionDuplicate` | The subscription that you are trying to create already exists. |\n| `badRequest (400)` | `subscriptionForbidden` | You have reached your maximum number of subscriptions. |\n| `badRequest (400)` | `subscriptionForbidden` | Subscribing to your own channel is not supported. |\n| `badRequest (400)` | `subscriptionForbidden` | Too many recent subscriptions. Please try again in a few hours. |\n| `forbidden (403)` | `subscriptionForbidden` | The request is not properly authenticated or not supported for this channel. |\n| `notFound (404)` | `publisherNotFound` | The resource specified by the request's `snippet.resourceId` property cannot be found. |\n| `notFound (404)` | `subscriberNotFound` | The subscriber identified with the request cannot be found. |\n| `required (400)` | `publisherRequired` | The subscription resource specified in the request must use the `snippet.resourceId` property to identify the channel that is being subscribed to. |\n\nTry it!\n-------\n\nUse the APIs Explorer to call this API and see the API request and response."]]