Implementation and Migration: Subscriptions

The following examples show how to use the YouTube Data API (v3) to perform functions related to subscriptions.

Retrieve a channel's subscriptions

YouTube Data API (v2) functionality: Retrieving a user's subscriptions

Call the subscriptions.list method to retrieve subscriptions for a particular channel. There are two ways to identify the channel:

Add a subscription

YouTube Data API (v2) functionality: Adding a subscription

Call the subscriptions.insert method to add a channel subscription. This request must be authorized using OAuth 2.0. The request body is a subscription resource that sets the following values:

The API request below subscribes you to the TED channel on YouTube:

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.insert?
        part=snippet

The request body is:

{
  "snippet": {
    "resourceId": {
      "kind": "youtube#channel",
      "videoId": "UCAuUUnT6oDeKwE6v1NGQxug"
    }
  }
}

Related code samples: Java, PHP, Python, Ruby

Delete a subscription

YouTube Data API (v2) functionality: Deleting a subscription

This example deletes a subscription. This request must be authorized using OAuth 2.0. This example has two steps:

  • Step 1: Retrieve the subscriptions for the authenticated user's channel

    Call the subscriptions.list method to retrieve the list of subscriptions. The example above for retrieving a channel's subscriptions explains how to make this request.

    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.

  • Step 2: Delete a subscription

    Call the subscriptions.delete method to delete a subscription. Set the request's id parameter to the subscription ID for the subscription that you want to remove. This request must be authorized using OAuth 2.0.

    To complete the request in the APIs Explorer, you need to set the id property's value.

    https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.delete?
            id=SUBSCRIPTION_ID

Retrieve a list of subscribers to the authorized user's channel

New in v3: This functionality is new in the v3 API.

To retrieve a list of channels that subscribe to the currently authenticated user's channel, call the subscriptions.list method and set the mySubscribers parameter's value to true. The request must be authorized using OAuth 2.0.

https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.list?
part=snippet,contentDetails
&mySubscribers=true

Enviar comentarios sobre…