ما در حال بهروزرسانی Data API هستیم تا با نحوه شمارش بازدیدهای YouTube برای Shorts مطابقت داشته باشد.
بیشتر بدانید
اجرا: اشتراک
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
مثالهای زیر نحوه استفاده از YouTube Data API (v3) را برای انجام عملکردهای مرتبط با اشتراکها نشان میدهند.
اشتراک های یک کانال را بازیابی کنید
اشتراک اضافه کنید
اشتراک را حذف کنید
این مثال یک اشتراک را حذف می کند. این درخواست باید با استفاده از OAuth 2.0 مجاز باشد. این مثال دو مرحله دارد:
مرحله 1: اشتراک های کانال کاربر احراز هویت شده را بازیابی کنید
برای بازیابی لیست اشتراک ها، روش subscriptions.list
را فراخوانی کنید. مثال بالا برای بازیابی اشتراک های یک کانال نحوه انجام این درخواست را توضیح می دهد.
برنامهای که API را فراخوانی میکند میتواند پاسخ API را پردازش کند تا فهرستی از اشتراکها را با استفاده از شناسه هر اشتراک به عنوان یک کلید نمایش دهد. در پاسخ، ویژگی id
هر مورد، شناسه اشتراک را مشخص می کند که به طور منحصر به فرد اشتراک مربوطه را مشخص می کند. شما از این مقدار برای حذف یک مورد از لیست در مرحله بعد استفاده خواهید کرد.
مرحله 2: اشتراک را حذف کنید
برای حذف اشتراک با روش subscriptions.delete
تماس بگیرید. پارامتر id
درخواست را روی شناسه اشتراک اشتراکی که میخواهید حذف کنید، تنظیم کنید. این درخواست باید با استفاده از OAuth 2.0 مجاز باشد.
برای تکمیل درخواست در APIs Explorer، باید مقدار ویژگی id
را تنظیم کنید.
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.subscriptions.delete?
id=SUBSCRIPTION_ID
برای نمونه کد به مستندات روش subscriptions.delete
مراجعه کنید.
فهرستی از مشترکین کانال کاربر مجاز را بازیابی کنید
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی."],[[["\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```"]]