165

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
- [email protected]
- fjTOrCPnAblTngWAzpnlMA

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

1
  • For those who come across this after the latest Data API revision (31st January, 2024), they provided the forHandle query parameter to get data of a handle/username. You can refer to this answer for details here: stackoverflow.com/a/78074066/2665606 Commented Feb 29 at 10:01

23 Answers 23

259

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.

13
  • 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
    Commented Apr 27, 2016 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
    Commented Jul 15, 2016 at 11:19
  • 22
    You may have to search "externalId" now as I couldn't find anything for "channel-external-id"
    – Daniel
    Commented Sep 22, 2017 at 6:16
  • 2
    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 Commented Sep 28, 2017 at 4:14
  • 17
    This also works: View page source and search <link rel="canonical". The href will contain the channel ID.
    – TD540
    Commented Nov 16, 2020 at 7:14
79

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.

4
  • I take it that it is not possible to get a channel ID without having an account ID. Is that correct?
    – mrub
    Commented May 17, 2015 at 7: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
    Commented May 18, 2015 at 20:48
  • Sorry, I was a bit unclear. I meant without actually having a google or youtube account.
    – mrub
    Commented May 27, 2015 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
    Commented May 27, 2015 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

2
  • 7
    As heads up for others reading this, it does not always work. See here and here
    – Simone
    Commented May 26, 2022 at 13:45
  • 1
    what is the username for this channel for example youtube.com/@kali-ka6998 ? can i use the youtube API to lookup the channel ID from it?
    – Colin D
    Commented Mar 11, 2023 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!

Edit:

Just in case you need UC channel id of any channel by the "YouTube handle", you can also use 'API Explorer' on the right of this page https://developers.google.com/youtube/v3/docs/channels/list and enter forHandle with your 'API key' (let me share screenshots below)

API key API Explorer channels/list
3
  • 4
    This should get more attention. Such a simple solution.
    – thyu
    Commented Jul 8, 2020 at 16:13
  • 8
    it is not working anymore Commented Jun 9, 2022 at 16:26
  • Hmm thank you for letting us know. Then I guess we have to open Developer Tools (cmd + option + I) and try to find the URL there
    – kangkyu
    Commented Jun 9, 2022 at 20:58
26

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

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.

1
  • 10
    It doesn't work anymore now.
    – 8oris
    Commented May 18, 2022 at 21:43
15

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
11

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
1
  • There is no need to specify the date, it is logged as part of the answer. Commented Aug 26, 2022 at 5:47
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];
}
3
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

6

2024 method using yt-dlp:

You can get YouTube channel ID from channel username:

yt-dlp --print "%(channel_id)s" --playlist-end 1 https://www.youtube.com/@CNN/
UCupvZG-5ko_eiXAupbDfxWw
5

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

enter image description here

1
  • 1
    This answer needs more recognition
    – Ghost Ops
    Commented Dec 7, 2022 at 18:13
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 .

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.

2

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)()

0
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}
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."
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

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
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.

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'.

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

-1

Now in 2023, typing this in console should work:

document.querySelectorAll('[itemprop="channelId"]')[0].content

Not the answer you're looking for? Browse other questions tagged or ask your own question.