चैनल आईडी के साथ काम करें
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
जेफ़ पॉस्निक, YouTube डेवलपर रिलेशनशिप – जून 2013
Google+ प्रोफ़ाइलों को YouTube चैनलों से लिंक करने की सुविधा, एक साल से ज़्यादा समय से उपलब्ध है. हमने ब्लॉग में बताया है कि प्रोफ़ाइल लिंक करने की वजह से, Data API v2 के कुछ रिस्पॉन्स कैसे बदल गए हैं. हाल ही में, ऐसे नए YouTube चैनल बनाने की सुविधा उपलब्ध हुई है जिनका कोई सामान्य YouTube उपयोगकर्ता नाम नहीं होता. इसके बजाय, उनकी पहचान सिर्फ़ Google+ प्रोफ़ाइल से की जाती है. उस ब्लॉग पोस्ट में दी गई ज़्यादातर जानकारी अब भी लागू है. हालांकि, इस बदलाव की वजह से YouTube चैनलों के बारे में कुछ बुनियादी मान्यताएं अमान्य हो गई हैं. जैसे, हर चैनल का यूनीक YouTube उपयोगकर्ता नाम होना चाहिए. इसलिए, हमने कुछ और सबसे सही तरीकों के बारे में बताना चाहा है, ताकि ऐसा कोड लिखा जा सके जो सभी तरह के चैनलों के साथ काम करे.
Data API v3 में चैनल आईडी
चैनलों के साथ काम करने वाले सभी v3 ऑपरेशन, चैनल आईडी का इस्तेमाल सिर्फ़ उन चैनलों की पहचान करने के लिए करते हैं. किसी YouTube उपयोगकर्ता के चैनल का आईडी, एपीआई के वर्शन 2 और वर्शन 3, दोनों में एक जैसा होता है. इससे, एक वर्शन से दूसरे वर्शन पर माइग्रेट करना आसान हो जाता है. चैनल आईडी पर पूरी तरह से निर्भर होना, उन डेवलपर के लिए परेशानी भरा हो सकता है जो पहले एपीआई के तरीकों में YouTube उपयोगकर्ता नाम डालते थे. हालांकि, v3 को इस तरह से डिज़ाइन किया गया था कि लेगसी उपयोगकर्ता नाम वाले और बिना लेगसी उपयोगकर्ता नाम वाले चैनलों को एक जैसा माना जाए. इसका मतलब है कि हर जगह चैनल आईडी का इस्तेमाल करना होगा.
अगर आपने v3 का इस्तेमाल किया है और आपको उस चैनल का आईडी वापस पाना है जिसके लिए फ़िलहाल अनुमति दी गई है, तो channels.list(part="id", mine=true)
का इस्तेमाल करें. यह v2 में, default
उपयोगकर्ता की चैनल प्रोफ़ाइल के बारे में पूछने के बराबर है.
अगर आपको कभी भी कोई ऐसा YouTube उपयोगकर्ता नाम मिलता है जिसे एपीआई के वर्शन 3 का इस्तेमाल करके चैनल आईडी में बदलना है, तो एपीआई को channels.list(part="id", forUsername="username")
कॉल किया जा सकता है.
अगर आपको सिर्फ़ डिसप्ले नेम पता है और आपको उससे जुड़ा चैनल ढूंढना है, तो search.list(part="snippet", type="channel", q="display name")
तरीका अपनाएं. आपको इस बात के लिए तैयार रहना चाहिए कि कॉल के जवाब में एक से ज़्यादा आइटम दिखें, क्योंकि डिसप्ले नेम यूनीक नहीं होते.
Data API v2 में चैनल आईडी
ध्यान दें: YouTube Data API (v2) को 26 फ़रवरी, 2014 से बंद कर दिया गया है. साथ ही, एपीआई को बंद कर दिया गया है. जिन ऐप्लिकेशन में अब भी v2 API का इस्तेमाल किया जा रहा है उन्हें तुरंत v3 API पर माइग्रेट कर देना चाहिए.
Data API v2 के पुराने वर्शन का इस्तेमाल करने वाले डेवलपर को यह ध्यान रखना चाहिए कि हर YouTube चैनल का यूनीक उपयोगकर्ता नाम नहीं होता. अच्छी बात यह है कि हर YouTube चैनल का एक यूनीक चैनल आईडी होता है. इसे <yt:channelId>
टैग की वैल्यू से दिखाया जाता है. हमारा सुझाव है कि डेवलपर, उपयोगकर्ता नाम के बजाय इस वैल्यू का इस्तेमाल करें. उदाहरण के लिए, अगर आपके पास कोई ऐसा डेटाबेस है जो YouTube उपयोगकर्ता नामों को उस चैनल की जानकारी से मैप करता है, तो आपकी पुरानी एंट्री काम करती रहेंगी. (मौजूदा चैनलों के यूज़र नेम नहीं बदलेंगे.) हालांकि, समय के साथ आपको ऐसे चैनलों के साथ काम करना पड़ सकता है जिनकी पहचान, यूज़र नेम से नहीं की जा सकती.
चैनल के नाम को चैनल आईडी में बदलने के लिए, कुछ बातों का ध्यान रखना ज़रूरी है. सबसे पहले, Data API v2 उन सभी अनुरोध यूआरएल में चैनल आईडी स्वीकार करता है जहां YouTube उपयोगकर्ता नाम स्वीकार किए जाते हैं. इसका मतलब है कि अपने मौजूदा कोड में चैनल आईडी को आसानी से बदला जा सकता है. उदाहरण के लिए, UC_x5XG1OV2P6uZZ5FSM9Ttw
, उस चैनल का चैनल आईडी है जिसका लेगसी उपयोगकर्ता नाम GoogleDevelopers
है. इसलिए, नीचे दिए गए दो यूआरएल, एपीआई के एक जैसे अनुरोध हैं:
https://gdata.youtube.com/feeds/api/users/GoogleDevelopers?v=2.1
https://gdata.youtube.com/feeds/api/users/UC_x5XG1OV2P6uZZ5FSM9Ttw?v=2.1
एक और बात ध्यान रखें कि जब भी पुष्टि किए गए v2 अनुरोध किए जा रहे हों, तो अनुरोध यूआरएल बनाते समय, अनुमति वाले चैनल का उपयोगकर्ता नाम शामिल करने की ज़रूरत नहीं होती. उपयोगकर्ता नाम (या चैनल आईडी) के बजाय, हमेशा 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 और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2024-11-23 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2024-11-23 (UTC) को अपडेट किया गया."],[[["\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`."]]