YouTube에서 Shorts 동영상의 조회수를 집계하는 방식에 맞게 Data API를 업데이트하고 있습니다.
자세히 알아보기
구현: 구독
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
다음 예에서는 YouTube Data API (v3)를 사용하여 구독과 관련된 기능을 실행하는 방법을 보여줍니다.
채널의 구독 항목 검색
구독 추가하기
구독 삭제
이 예시에서는 구독을 삭제합니다. 이 요청은 OAuth 2.0을 사용하여 승인해야 합니다. 이 예시에는 두 단계가 있습니다.
코드 샘플은 subscriptions.delete
메서드 문서를 참고하세요.
승인된 사용자의 채널 구독자 목록 가져오기
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-11-23(UTC)
[null,null,["최종 업데이트: 2024-11-23(UTC)"],[[["\u003cp\u003eThe YouTube Data API (v3) allows retrieving a list of subscriptions for a channel using the \u003ccode\u003esubscriptions.list\u003c/code\u003e method, either for the authenticated user's channel (using \u003ccode\u003emine=true\u003c/code\u003e) or for another channel (using \u003ccode\u003echannelId\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eTo add a channel subscription, you can use the \u003ccode\u003esubscriptions.insert\u003c/code\u003e method, providing the \u003ccode\u003eyoutube#channel\u003c/code\u003e kind and the target channel's ID in the request body's \u003ccode\u003esnippet.resourceId\u003c/code\u003e property, while also needing to be authorized using OAuth 2.0.\u003c/p\u003e\n"],["\u003cp\u003eDeleting a channel subscription involves first retrieving the subscription list using \u003ccode\u003esubscriptions.list\u003c/code\u003e to find the subscription ID, and then using \u003ccode\u003esubscriptions.delete\u003c/code\u003e with that ID to remove the subscription, which requires OAuth 2.0 authorization.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003esubscriptions.list\u003c/code\u003e method can also be utilized to retrieve a list of channels that subscribe to the currently authenticated user's channel by setting the \u003ccode\u003emySubscribers\u003c/code\u003e parameter to \u003ccode\u003etrue\u003c/code\u003e, while needing to be authorized using OAuth 2.0.\u003c/p\u003e\n"]]],["The YouTube Data API (v3) manages subscriptions via the `subscriptions` resource. To retrieve subscriptions, use `subscriptions.list`, setting `mine` to `true` for the authenticated user or `channelId` for others. Adding subscriptions involves `subscriptions.insert`, specifying `youtube#channel` and the target `channelId`. To delete, use `subscriptions.delete` after using `subscriptions.list` to identify the subscription `id`. Retrieve a list of a channel subscribers by calling `subscriptions.list` and setting the `mySubscribers` to `true`. All actions except by channelId require OAuth 2.0.\n"],null,["# Implementation: Subscriptions\n\nThe following examples show how to use the YouTube Data API (v3) to perform functions related to subscriptions.\n\nRetrieve a channel's subscriptions\n----------------------------------\n\nCall the [subscriptions.list](/youtube/v3/docs/subscriptions/list) method to retrieve subscriptions for a particular channel. There are two ways to identify the channel:\n\n- To retrieve the currently authenticated user's subscriptions, set the [mine](/youtube/v3/docs/subscriptions/list#mine) parameter's value to `true`. Note that a request that uses the `mine` parameter must be authorized using OAuth 2.0.\n\n ```\n https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?\n part=snippet,contentDetails\n &mine=true\n ```\n- To retrieve subscriptions for any other channel, set the [channelId](/youtube/v3/docs/subscriptions/list#channelId) parameter's value to that channel's unique YouTube channel ID. The example below retrieves a list of channels subscribed to by the TED channel on YouTube.\n\n ```\n https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?\n part=snippet,contentDetails\n &channelId=UCAuUUnT6oDeKwE6v1NGQxug\n ```\n\n **Note:** The API returns a `403 (Forbidden)` HTTP response code if the specified channel does not publicly expose its subscriptions and the request is not authorized by the channel's owner.\n\nSee the [subscriptions.list](/youtube/v3/docs/subscriptions/list#usage) method's documentation for code samples.\n\nAdd a subscription\n------------------\n\nCall the [subscriptions.insert](/youtube/v3/docs/subscriptions/insert) method to add a channel subscription. This request must be authorized using OAuth 2.0. The request body is a [subscription](/youtube/v3/docs/subscriptions) resource that sets the following values:\n\n\u003cbr /\u003e\n\n- The [snippet.resourceId.kind](/youtube/v3/docs/subscriptions#snippet.resourceId.kind) contains the value `youtube#channel`.\n- The [snippet.resourceId.channelId](/youtube/v3/docs/subscriptions#snippet.resourceId.channelId) property identifies the channel that is being subscribed to. The property value is a unique YouTube channel ID. The channel ID could be obtained in multiple ways, including calling the [channels.list](/youtube/v3/docs/channels/list) method or retrieving [search results for channels](/youtube/v3/docs/search/list).\n\n\u003cbr /\u003e\n\nThe API request below subscribes you to the TED channel on YouTube: \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.insert?\n part=snippet\n```\n\nThe request body is: \n\n```\n{\n \"snippet\": {\n \"resourceId\": {\n \"kind\": \"youtube#channel\",\n \"videoId\": \"UCAuUUnT6oDeKwE6v1NGQxug\"\n }\n }\n}\n```\n\nSee the [subscriptions.insert](/youtube/v3/docs/subscriptions/insert#usage) method's documentation for code samples.\n\nDelete a subscription\n---------------------\n\nThis example deletes a subscription. This request must be authorized using OAuth 2.0. This example has two steps:\n\n- **Step 1: Retrieve the subscriptions for the authenticated user's channel**\n\n Call the [subscriptions.list](/youtube/v3/docs/subscriptions/list) method to retrieve the list of subscriptions. The example above for retrieving a channel's subscriptions explains how to make this request.\n\n The application calling the API could process the API response to display a list of subscriptions, using each subscription's ID as a key. In the response, each item's `id` property identifies the subscription ID that uniquely identifies the corresponding subscription. You will use that value to remove an item from the list in the next step.\n- **Step 2: Delete a subscription**\n\n Call the [subscriptions.delete](/youtube/v3/docs/subscriptions/delete) method to delete a subscription. Set the request's [id](/youtube/v3/docs/subscriptions/delete#id) parameter to the subscription ID for the subscription that you want to remove. This request must be authorized using OAuth 2.0.\n\n To complete the request in the APIs Explorer, you need to set the `id` property's value. \n\n ```\n https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.delete?\n id=SUBSCRIPTION_ID\n ```\n\nSee the [subscriptions.delete](/youtube/v3/docs/subscriptions/delete#usage) method's documentation for code samples.\n\nRetrieve a list of subscribers to the authorized user's channel\n---------------------------------------------------------------\n\nTo retrieve a list of channels that subscribe to the currently authenticated user's channel, call the `subscriptions.list` method and set the [mySubscribers](/youtube/v3/docs/subscriptions/list#mySubscribers) parameter's value to `true`. The request must be authorized using OAuth 2.0. \n\n```\nhttps://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?\n part=snippet,contentDetails\n &mySubscribers=true\n```"]]