ما در حال بهروزرسانی Data API هستیم تا با نحوه شمارش بازدیدهای YouTube برای Shorts مطابقت داشته باشد.
بیشتر بدانید
با شناسه های کانال کار کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
جف پوسنیک، روابط توسعهدهنده YouTube - ژوئن 2013
بیش از یک سال است که میتوان نمایههای +Google را با کانالهای YouTube پیوند داد، و ما در مورد اینکه چگونه برخی از پاسخهای Data API v2 در نتیجه پیوند نمایه تغییر کردهاند، وبلاگنویسی کردهایم . اخیراً، ایجاد کانالهای YouTube جدید که نام کاربری سنتی YouTube با آنها مرتبط نیست و در عوض، تنها با نمایه +Google آنها شناسایی میشوند، ممکن شده است. بسیاری از اطلاعات آن پست وبلاگ همچنان اعمال می شود، اما این چین و چروک اضافی برخی از مفروضات اساسی در مورد کانال های YouTube را باطل می کند - مانند اینکه هر کدام همیشه با یک نام کاربری منحصر به فرد YouTube مرتبط هستند - و ما می خواستیم برخی از بهترین روش های اضافی را دنبال کنیم. کدی بنویسید که با تمام سلیقه های کانال کار کند.
شناسههای کانال در Data API نسخه 3
تمام عملیات نسخه 3 که با کانال ها کار می کنند از شناسه کانال منحصراً به عنوان وسیله ای برای شناسایی آن کانال ها استفاده می کنند. شناسه کانال یک کاربر YouTube خاص در نسخه 2 و 3 API یکسان است و انتقال بین نسخه ها را ساده می کند. این اتکای کامل به شناسههای کانال ممکن است برای توسعهدهندگانی که قبلاً به انتقال نامهای کاربری YouTube به روشهای API عادت داشتند، گیجکننده باشد، اما نسخه 3 برای برخورد یکسان با کانالهای دارای نام کاربری قدیمی و بدون نام کاربری قدیمی طراحی شده است و این به معنای استفاده از شناسه کانال در همه جا است.
اگر از نسخه 3 استفاده می کنید و می خواهید شناسه کانال مربوط به کاربر مجاز فعلی را بازیابی کنید، می توانید با روش channels.list(part="id", mine=true)
تماس بگیرید. این معادل درخواست نمایه کانال کاربر default
در نسخه 2 است.
اگر زمانی با نام کاربری دلخواه و قدیمی YouTube مواجه شدید که باید آن را با استفاده از نسخه 3 API به یک شناسه کانال ترجمه کنید، میتوانید یک channels.list(part="id", forUsername=" username ")
تماس بگیرید API.
اگر فقط یک نام نمایشی می دانید و به دنبال یافتن کانال مربوطه هستید، روش search.list(part="snippet", type="channel", q=" display name ")
مفید خواهد بود. شما باید آماده باشید تا با امکان پاسخگویی تماس به بیش از یک مورد در پاسخ، مقابله کنید، زیرا نام های نمایشی منحصر به فرد نیستند.
شناسههای کانال در Data API v2
توجه: YouTube Data API (v2) از 26 فوریه 2014 منسوخ شده است و API رد شده است. برنامه هایی که هنوز از v2 API استفاده می کنند باید فوراً به API v3 مهاجرت کنند.
بزرگترین نکته برای توسعه دهندگانی که از Data API نسخه 2 قدیمی استفاده می کنند این است که باید بدانید که هر کانال YouTube یک نام کاربری منحصر به فرد ندارد . خوشبختانه، هر کانال YouTube تضمین شده است که یک شناسه کانال منحصر به فرد مرتبط با آن داشته باشد، که با مقدار موجود در تگ <yt:channelId>
نشان داده شده است، و این مقداری است که ما به توسعه دهندگان توصیه می کنیم به جای نام کاربری از آن استفاده کنند. برای مثال، اگر پایگاه دادهای دارید که نامهای کاربری YouTube را به اطلاعات مربوط به آن کانال نگاشت میکند، ورودیهای قدیمیتر شما باید به کار خود ادامه دهند. (کانالهای موجود نام کاربری خود را از دست نمیدهند.) با این حال، با گذشت زمان، این احتمال بیشتر و بیشتر میشود که مجبور شوید با کانالهایی کار کنید که نمیتوانند به طور منحصربهفرد با نام کاربری شناسایی شوند.
چند عامل انتقال از نام کاربری به شناسه کانال را ساده می کند. ابتدا، Data API v2 شناسههای کانال را در URLهای درخواستی هر جا که نامهای کاربری YouTube را میپذیرد، میپذیرد، به این معنی که میتوانید به طور یکپارچه شناسه کانال را با کد موجود خود عوض کنید. برای مثال، از آنجایی که UC_x5XG1OV2P6uZZ5FSM9Ttw
شناسه کانال برای کانال با نام کاربری قدیمی GoogleDevelopers
است، دو نشانی وب زیر درخواستهای API معادل هستند:
https://gdata.youtube.com/feeds/api/users/GoogleDevelopers?v=2.1
https://gdata.youtube.com/feeds/api/users/UC_x5XG1OV2P6uZZ5FSM9Ttw?v=2.1
نکته دیگری که باید در نظر داشته باشید این است که هر زمان که درخواستهای تایید شده نسخه 2 را انجام میدهید، هرگز نیازی به وارد کردن نام کاربری کانال مجاز در هنگام ساخت URL های درخواستی ندارید. همیشه می توانید مقدار default
را به جای نام کاربری (یا شناسه کانال) استفاده کنید. بنابراین، برای مثال، اگر میخواهید فید آپلود ویدیو را برای کاربر مجاز فعلی بازیابی کنید، میتوانید این کار را در https://gdata.youtube.com/feeds/api/users/default/uploads?v=2.1
انجام دهید.
جز در مواردی که غیر از این ذکر شده باشد،محتوای این صفحه تحت مجوز Creative Commons Attribution 4.0 License است. نمونه کدها نیز دارای مجوز Apache 2.0 License است. برای اطلاع از جزئیات، به خطمشیهای سایت Google Developers مراجعه کنید. جاوا علامت تجاری ثبتشده Oracle و/یا شرکتهای وابسته به آن است.
تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2024-11-23 بهوقت ساعت هماهنگ جهانی."],[[["\u003cp\u003eYouTube channels can now be identified solely by their Google+ profile, without a traditional YouTube username.\u003c/p\u003e\n"],["\u003cp\u003eThe YouTube Data API v3 exclusively uses channel IDs to identify channels, offering consistency for channels with or without legacy usernames.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use the \u003ccode\u003echannels.list\u003c/code\u003e method in v3 to retrieve a channel ID based on the authorized user or a legacy username.\u003c/p\u003e\n"],["\u003cp\u003eIn v2, it's crucial to recognize that not every YouTube channel has a unique username, but all have a unique channel ID, which is the recommended identifier.\u003c/p\u003e\n"],["\u003cp\u003eThe deprecated Data API v2 can use channel IDs in place of usernames in request URLs, and \u003ccode\u003edefault\u003c/code\u003e can be used instead of usernames for authenticated v2 requests.\u003c/p\u003e\n"]]],["YouTube introduced channels solely identified by Google+ profiles, lacking traditional usernames. Data API v3 exclusively uses channel IDs to identify channels, simplifying the process for developers. To get the authorized user's channel ID, use `channels.list(part=\"id\", mine=true)`. To translate a username to a channel ID, use `channels.list(part=\"id\", forUsername=\"username\")`. For display names, use `search.list(part=\"snippet\", type=\"channel\", q=\"display name\")`. Data API v2, now deprecated, also utilizes channel IDs, allowing them to replace usernames in requests.\n"],null,["# Work with Channel IDs\n\n*Jeff Posnick, YouTube Developer Relations -- June 2013*\nFor more than a year, it's been possible to link Google+ profiles with YouTube channels, and we've [blogged](http://apiblog.youtube.com/2012/03/youtube-google-api-and-you.html) about how some of the Data API v2 responses have changed as a result of that profile link. More recently, it has become possible to create new YouTube channels that don't have a traditional YouTube username associated with them and, instead, are [solely identified by their Google+ profile](http://youtubecreator.blogspot.com/2013/04/using-google-page-identity-on-youtube.html). Much of the information from that blog post still applies, but this extra wrinkle does invalidate some fundamental assumptions about YouTube channels -- like that each one will always be associated with a unique YouTube username -- and we wanted to follow up with some additional best practices to write code that works with all flavors of channels.\n\nChannel IDs in the Data API v3\n------------------------------\n\nAll v3 operations that work with channels use [channel IDs](/youtube/v3/docs/channels#id) exclusively as a means of identifying those channels. The ID for a specific YouTube user's channel is identical in both v2 and v3 of the API, simplifying migrations between versions. This complete reliance on channel IDs might be perplexing for developers who were previously used to passing YouTube usernames to API methods, but v3 was designed to treat channels with and without legacy usernames identically, and that means using channel IDs everywhere.\n\nIf you are using v3 and want to retrieve the channel ID that corresponds to the currently authorized user, you can call the [channels.list(part=\"id\", mine=true)](https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list?part=id&mine=true) method. This is equivalent to asking for the channel profile of the `default` user in v2.\n\nIf you ever do find yourself with an arbitrary legacy YouTube username that you need to translate into a channel ID using v3 of the API, you can make a [channels.list(part=\"id\", forUsername=\"\u003cvar class=\"apiparam\" translate=\"no\"\u003eusername\u003c/var\u003e\")](https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.channels.list?part=id&forUsername=YouTubeDev) call to the API.\n\nIf you only know a display name and are looking to find the corresponding channel, the [search.list(part=\"snippet\", type=\"channel\", q=\"\u003cvar class=\"apiparam\" translate=\"no\"\u003edisplay name\u003c/var\u003e\")](https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.search.list?part=snippet&q=YouTube+for+Developers&type=channel) method will come in handy. You should be prepared to deal with the possibility of the call returning more than one item in the response, since display names are not unique.\n\nChannel IDs in the Data API v2\n------------------------------\n\n**Note:** The YouTube Data API (v2) has been deprecated since February 26, 2014, and the API has been [turned down](http://youtube-eng.blogspot.com/2015/04/bye-bye-youtube-data-api-v2.html). Applications still using the v2 API should migrate to the v3 API immediately.\n\nThe biggest takeaway for developers using the older [Data API v2](/youtube/2.0/developers_guide_protocol_audience) is that you must be aware that **not every YouTube channel has a unique username** . Fortunately, every YouTube channel is guaranteed to have a unique channel ID associated with it, represented by the value in the [`\u003cyt:channelId\u003e` tag](/youtube/2.0/reference#youtube_data_api_tag_yt:channelId), and that's the value that we recommend developers use instead of usernames. For instance, if you have a database that maps YouTube usernames to information about that channel, your older entries should continue to work. (Existing channels won't lose their usernames.) However, as time goes on, it will become more and more likely that you'll have to work with channels that can't be uniquely identified by a username.\n\nA couple of factors simplify the transition from usernames to channel IDs. First, the Data API v2 accepts channel IDs in request URLs wherever it accepts YouTube usernames, meaning that you can seamlessly swap a channel ID into your existing code. For example, since `UC_x5XG1OV2P6uZZ5FSM9Ttw` is the channel ID for the channel with the legacy username `GoogleDevelopers`, the following two URLs are equivalent API requests: \n\n https://gdata.youtube.com/feeds/api/users/GoogleDevelopers?v=2.1\n https://gdata.youtube.com/feeds/api/users/UC_x5XG1OV2P6uZZ5FSM9Ttw?v=2.1\n\nAnother thing to keep in mind is that whenever you're making [authenticated](/youtube/2.0/developers_guide_protocol_authentication) v2 requests, you never need to include the authorized channel's username when constructing request URLs. You can always use the value `default` in place of a username (or channel ID). So if you want to retrieve the video uploads feed for the currently authorized user, for instance, you can do so at `https://gdata.youtube.com/feeds/api/users/default/uploads?v=2.1`."]]