Data API'yi, YouTube'un Shorts görüntülemelerini sayma şekliyle eşleşecek şekilde güncelliyoruz.
Daha fazla bilgi
Uygulama: Abonelikler
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
Aşağıdaki örneklerde, aboneliklerle ilgili işlevleri gerçekleştirmek için YouTube Data API'nin (v3) nasıl kullanılacağı gösterilmektedir.
Kanal aboneliklerini alma
Belirli bir kanalın aboneliklerini almak için subscriptions.list
yöntemini çağırın. Kanalı tanımlamanın iki yolu vardır:
Kod örnekleri için subscriptions.list
yönteminin dokümanlarına bakın.
Abonelik ekleme
Aboneliği silme
Bu örnekte bir abonelik siliniyor. Bu istek, OAuth 2.0 kullanılarak yetkilendirilmelidir. Bu örnekte iki adım vardır:
-
1. adım: Kimliği doğrulanmış kullanıcının kanalının aboneliklerini alın
Aboneliklerin listesini almak için subscriptions.list
yöntemini çağırın. Yukarıdaki kanal aboneliklerini alma örneğinde bu isteğin nasıl yapılacağı açıklanmaktadır.
API'yi çağıran uygulama, API yanıtını işleyebilir ve her aboneliğin kimliğini anahtar olarak kullanarak aboneliklerin listesini görüntüleyebilir. Yanıtta, her öğenin id
mülkü, ilgili aboneliği benzersiz şekilde tanımlayan abonelik kimliğini tanımlar. Bir sonraki adımda listeden öğe kaldırmak için bu değeri kullanacaksınız.
-
2. Adım: Aboneliği silin
Aboneliği silmek için subscriptions.delete
yöntemini çağırın. İsteğin id
parametresini, kaldırmak istediğiniz aboneliğin abonelik kimliğine ayarlayın. Bu istek, OAuth 2.0 kullanılarak yetkilendirilmelidir.
İsteği APIs Explorer'da tamamlamak için id
mülkünün değerini ayarlamanız gerekir.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.delete?
id=SUBSCRIPTION_ID
Kod örnekleri için subscriptions.delete
yönteminin dokümanlarına bakın.
Yetkili kullanıcının kanalına abone olan kullanıcıların listesini alma
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2024-11-23 UTC.
[null,null,["Son güncelleme tarihi: 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```"]]