154

I'm trying to retrive the data from my channel using the YouTube Data API V3.
For that I need my channel ID.
I've tried to find my channel ID from my YouTube account, and I failed in every single way.
If anyone have a single tip for me, I would be incredible glad.

This is the URL that I'm using to retrieve the data:

https://www.googleapis.com/youtube/v3/channels?id=fjTOrCPnAblTngWAzpnlMA&key={YOUR_API_KEY}&part=snippet,contentDetails,statistics

The ID is for the channel ID, and the key, I'm replacing the {YOUR_API_KEY} with my API KEY generated at my Google API console.

My channel ID is not:
- klauskkpm
- klausmachado
- klausmachado@gmail.com
- fjTOrCPnAblTngWAzpnlMA

My channel is: http://www.youtube.com/user/klauskkpm

Peter O.
  • 32,158
  • 14
  • 82
  • 96
klauskpm
  • 2,965
  • 2
  • 18
  • 29

22 Answers22

251

To obtain the channel id you can view the source code of the channel page and find either data-channel-external-id="UCjXfkj5iapKHJrhYfAF9ZGg" or "externalId":"UCjXfkj5iapKHJrhYfAF9ZGg".

UCjXfkj5iapKHJrhYfAF9ZGg will be the channel ID you are looking for.

Lemmings19
  • 1,383
  • 3
  • 21
  • 34
Henry Moshkovich
  • 2,562
  • 2
  • 13
  • 4
  • 6
    @Naveed Ahmad as this answer helps, view(in this case HTML) should not be used, since it's not reliable. They don't offer their HTML versionated or give an API access to it in anyway. To get any YouTube channel id, is wise to use the **mjlescano** answer, which uses the YouTube API. – klauskpm Apr 27 '16 at 18:56
  • 2
    @klauskpm true, since you were looking for your own id, but this answer gets you any channel ID and still does it 3 years later :) – Yevgeniy Jul 15 '16 at 11:19
  • @Yevgeniy, if you read my comment above, I told that it helps, but **mijlescano** answer can provide that using the official API, which is recommended. – klauskpm Jul 15 '16 at 12:25
  • Can you get a channel username using the channel ID? – BigMonkey89WithaLeg Jun 20 '17 at 05:49
  • 20
    You may have to search "externalId" now as I couldn't find anything for "channel-external-id" – Daniel Sep 22 '17 at 06:16
  • 1
    After getting a bunch of YouTube channel ids manually, it looks like `data-channel-external-id` is for older channels (channels that were created *before* a certain date) and `externalId` is for newer channels (channels that were created *after* a certain date). I'm not sure when this "certain date" is, but if one doesn't work for you - try the other one – derekantrican Sep 28 '17 at 04:14
  • This worked well. I did not have YouTube Channel login details for the client & this saved my time. Thank you. – tushonline Jul 25 '18 at 17:19
  • I just tried this on a channel that had the ID `UCW_OAaMdUH3fF00fh8_Koeg`. Their automatic "all uploads" playlist (which you can get to by clicking "play all" on the videos section of the channel) has the ID `UUW_OAaMdUH3fF00fh8_Koeg`. I don't know if it's always the same, but with U vs. C, but it might be. – Fabian Röling Nov 04 '20 at 10:32
  • 12
    This also works: View page source and search ` – TD540 Nov 16 '20 at 07:14
  • Doesn't work for not logged user – Atsuo Sakakihara Mar 12 '22 at 11:50
  • Also works searching on the html for "og:user" then you can get the full url with the respective channel id. – Manoel Stilpen May 27 '22 at 21:32
  • It's the string of characters after `l_id=`. – Paul Aug 04 '22 at 20:06
  • Adding another method I just found: `` – Glenn 'devalias' Grant Apr 19 '23 at 03:20
78

An easy answer is, your YouTube Channel ID is UC + {YOUR_ACCOUNT_ID}. To be sure of your YouTube Channel ID or your YouTube account ID, access the advanced settings at your settings page

And if you want to know the YouTube Channel ID for any channel, you could use the solution @mjlescano gave.

https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername={USER_NAME}&part=id

If this could be of any help, some user marked it was solved in another topic right here.

Asclepius
  • 57,944
  • 17
  • 167
  • 143
klauskpm
  • 2,965
  • 2
  • 18
  • 29
  • I take it that it is not possible to get a channel ID without having an account ID. Is that correct? – mrub May 17 '15 at 07:10
  • The account ID and channel ID can be very similar, taking the UC part. As I've said, you can enter the advanced settings page of your youtube account, or channel, and it will show you both IDs. Each channel/account creates both new channel and account ID. So, they will ever exist. – klauskpm May 18 '15 at 20:48
  • Sorry, I was a bit unclear. I meant without actually having a google or youtube account. – mrub May 27 '15 at 12:02
  • Yes. If your trying to get your Channel ID ou Account ID, and you don't have an account or channel, both will not exist. Still, you can get this information for other channels. There is an example above. – klauskpm May 27 '15 at 21:14
32

You can get the channel ID with the username (in your case "klauskkpm") using the filter "forUsername", like this:

https://www.googleapis.com/youtube/v3/channels?key={YOUR_API_KEY}&forUsername=klauskkpm&part=id

More info here: https://developers.google.com/youtube/v3/docs/channels/list

mjlescano
  • 847
  • 9
  • 13
  • 6
    As heads up for others reading this, it does not always work. See [here](https://stackoverflow.com/questions/62576403/how-to-get-a-youtube-channel-id-from-the-channels-username-which-includes-cyril) and [here](https://stackoverflow.com/questions/37267324/how-to-get-youtube-channel-details-using-youtube-data-api-if-channel-has-custom) – Simone May 26 '22 at 13:45
  • what is the username for this channel for example https://www.youtube.com/@kali-ka6998 ? can i use the youtube API to lookup the channel ID from it? – Colin D Mar 11 '23 at 19:57
30

At any channel page with "user" url for example http://www.youtube.com/user/klauskkpm, without API call, from YouTube UI, click a video of the channel (in its "VIDEOS" tab) and click the channel name on the video. Then you can get to the page with its "channel" url for example https://www.youtube.com/channel/UCfjTOrCPnAblTngWAzpnlMA.

Edit:

Above is not working any more. But we can open Developer Tools (cmd + option + I) and try to find the URL there. Search by channel_id for some channels, it will show you, but NOT for all the channels.

By the way, if this is your own channel -- you can go here https://developers.google.com/youtube/v3/docs/channels/list and make request with part snippet and mine true.

Oh, I found this answer. Thank you, just works!

kangkyu
  • 5,252
  • 3
  • 34
  • 36
20

I just found the simplest way to find the channel ID of any YouTube channel !!

Step 1: Play a video of that channel.

Step 2: Click the channel name under that video.

Step 3: Look at the browser address bar.

LinuxBabe
  • 387
  • 2
  • 6
16

June 2021 edition.

  1. Right click and view page source.
  2. Search for "externalId", the value follows.

Source: comment by Daniel 2017.

Alternative: run this JavaScript in console:

ytInitialData.metadata.channelMetadataRenderer.externalId
Avindra Goolcharan
  • 4,032
  • 3
  • 41
  • 39
12

Update: 2023

  1. Go to the About Tab of the YouTube channel

  2. Under the Stats section click the Share button and select Copy Channel ID.

enter image description here

Kostas Minaidis
  • 4,681
  • 3
  • 17
  • 25
10

An alternative to get youtube channel ID by channel url without API:

function get_youtube_channel_ID($url){
  $html = file_get_contents($url);
  preg_match("'<meta itemprop=\"channelId\" content=\"(.*?)\"'si", $html, $match);
  if($match && $match[1])
    return $match[1];
}
Avindra Goolcharan
  • 4,032
  • 3
  • 41
  • 39
Arthur Ronconi
  • 2,290
  • 25
  • 25
9

As of 2022-06-23:

Open Chrome Dev Tools (F12), and in the "Elements" tab, within the source code pane, depending on URL type:

A. For channel URLs of type: www.youtube.com/c/<channel_name>:

Search for either:

or run in the console:

ytInitialData.metadata.channelMetadataRenderer.externalId

(credit: https://stackoverflow.com/a/68063136/624597)

B. For video URLs of type: www.youtube.com/watch?v=<video_ID>:

Search for either:

  • "externalId" - next to it there will be the channel_ID
  • "externalChannelId" - next to it there will be the channel_ID
  • "ownerProfileUrl" - next to it there will be: https://www.youtube.com/channel/<channel_ID>

or run in the console:

ytInitialPlayerResponse.microformat.playerMicroformatRenderer.externalChannelId
ellockie
  • 3,730
  • 6
  • 42
  • 44
6

Channel id with the current youtube version is obtained very easily if you login to YouYube website and select 'My channel'

My channel

Your channel ID will be displayed on the address bar of your browser channel id

Vas Giatilis
  • 1,086
  • 12
  • 16
3

https://www.youtube.com/account_advanced now provides both channel and user ids. See also https://developers.google.com/youtube/v3/guides/working_with_channel_ids .

Dan Jacobson
  • 490
  • 3
  • 14
3

2017 Update: Henry's answer may be a little off the mark here. If you look for data-channel-external-id in the source code you may find more than one ID, and only the first occurrence is actually correct. Get the channel_id used in <link rel="alternate" type="application/rss+xml" title="RSS" href="https://www.youtube.com/feeds/videos.xml?channel_id=<VALUE_HERE"> instead.

Community
  • 1
  • 1
vitorrrr
  • 70
  • 7
3

Apparently there is a channelId attribute in video page's source code;

enter image description here

Mechanic
  • 5,015
  • 4
  • 15
  • 38
1

To obtain the channel id you can do the following request which gives you the channel id and playlist id.

https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2C+statistics%2Csnippet&mine=true&key={YOUR_API_KEY}

mine parameter means the current authorized user

as u said channel id is prefixed with UC+{your account id} which you get while login, you can use this one also without requesting the above url you can directly call the channel api with your google id and just prefix with UC

https://www.googleapis.com/youtube/v3/channels?part=contentDetails%2C+statistics%2Csnippet&id=UC{your account id}&key={YOUR_API_KEY}
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
rakesh r
  • 465
  • 2
  • 4
  • 12
1

I have actually created the python function to help with obtaining the id of, it seems, any youtube channel. It uses requests (to get the raw html of the page) and beautifulsoup (to deal with this html and find this cagey id). Yes, it doesn't use any official API and therefore it`s less stable (because it relies on the structure of the youtube webpage), but, I think, this solution can still be helpful.

import requests
from bs4 import BeautifulSoup

def get_yt_channel_id(modern_url: str):
    soup = BeautifulSoup(requests.get(modern_url).content, "html.parser")
    try:
        return soup.find("meta", {"itemprop": "channelId"})["content"]
    except TypeError:
        return "Seems like the link is not valid."

while True:
    link = input("> ")
    print(get_yt_channel_id(modern_url=link))

To make this program work, you need to just insert the modern link (with @, e.: https://www.youtube.com/@KlausKazlauskas/videos), but it`s possible to modify this so that the function only takes the username:

def get_yt_channel_id(username: str):
    modern_url = f"https://www.youtube.com/@{username}"
    soup = BeautifulSoup(requests.get(modern_url).content, "html.parser")
    try:
        return soup.find("meta", {"itemprop": "channelId"})["content"]
    except TypeError:
        return "Seems like the username is not valid."
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Deep Drop
  • 29
  • 6
0

To get Channel id

Ex: Apple channel ID

enter image description here

Select any of the video in that channel

enter image description here

Select iPhone - Share photos (video)

Now click on channel name Apple bottom of the video.

enter image description here

Now you will get channel id in browser url

enter image description here

Here this is Apple channel id: UCE_M8A5yxnLfW0KghEeajjw

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Naresh
  • 16,698
  • 6
  • 112
  • 113
0

Try to search for regular expression UC[-_0-9A-Za-z]{21}[AQgw] in source code. This ID is presented even if channel has non-ASCII characters in URL:

enter image description here

Here is screenshot of internal viewer/editor of Midnight Commander, it has regexp search:

enter image description here

shoorick
  • 129
  • 3
0

Alternatives to get the channel URL with its ID.

With a CSS selector by searching the channel homepage source code:

body > link[rel="canonical"]

or with JS via the console:

document.querySelector('body > link[rel="canonical"]').href
Stéphane Bruckert
  • 21,706
  • 14
  • 92
  • 130
0

Another method to find the ID of a channel that is not yours is to go to the channel page and press the red "Subscribe" button.

enter image description here

Then use the Chrome's Inspector tools Network tab and look for the POST request issued by the subscribe action. In the payload of this request you will find the channel id:

enter image description here

You can unsubscribe immediately after subscribing.

gil.fernandes
  • 12,978
  • 5
  • 63
  • 76
0

I found a helpful solution here. First, you need to use the search endpoint with the username as a query parameter. Then you will be able to get the 'youtube#channel' section, along with the 'channelId'.

calvo215
  • 23
  • 6
0

A most simple solution for 2023 is just to get ID from meta tags:

Just run this snippet in Channel page and it will alert the id for you to copy&paste:

alert(document.querySelector('meta[property="og:url"]').getAttribute('content').split('/').at(4))

To keep things easy, I personally made a bookmarklet for myself using this code, so I could run it any time without opening the dev tools.

A code for bookmarklet:

javascript:(function()%7Balert(document.querySelector('meta%5Bproperty%3D%22og%3Aurl%22%5D').getAttribute('content').split('%2F').at(4))%7D)()

xb1itz
  • 1,022
  • 10
  • 17
-1

Now in 2023, typing this in console should work:

document.querySelectorAll('[itemprop="channelId"]')[0].content
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
Vladan
  • 725
  • 8
  • 13