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
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.
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.
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
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.
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.
June 2021 edition.
Right click and view page source.
Search for "externalId", the value follows.
Source: comment by Daniel 2017.
Alternative: run this JavaScript in console:
ytInitialData.metadata.channelMetadataRenderer.externalId
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];
}
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:
"externalId" - next to it there will be the channel_ID
"channelUrl" - next to it there will be: https://www.youtube.com/channel/<channel_ID>
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
Channel id with the current youtube version is obtained very easily if you login to YouYube website and select 'My channel'
Your channel ID will be displayed on the address bar of your browser
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 .
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.
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}
Apparently there is a channelId attribute in video page's source code;
To get Channel id
Ex: Apple channel ID
Select any of the video in that channel
Select iPhone - Share photos (video)
Now click on channel name Apple bottom of the video.
Now you will get channel id in browser url
Here this is Apple channel id : UCE_M8A5yxnLfW0KghEeajjw
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:
Here is screenshot of internal viewer/editor of Midnight Commander, it has regexp search:
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
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.
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:
You can unsubscribe immediately after subscribing.
Now in 2023, typing this in console should work:
document.querySelectorAll('[itemprop="channelId"]')[0].content
Related
I am fetching all the Accounts that have subscribed to the authenticated user's channel.
Is there a way to obtain the timestamp of when the user has subscribed to the channel?
The default "publishedAt" sadly is of no help because that seems to be the timestamp of when the channel was created.
Also, that is not part of the "subscriberSnippet"-Section
Twitch and Mixer both provide "created_at", but the YouTube-API is a whole other story...
Thank you very much,
~ Daniel
Based from the official documentation of Youtube API:
Subscriptions: list
retrieves a list of channels that the specified channel subscribes to.
You can view here the subscriptions resource and publishedAt is part of it:
snippet.publishedAt datetime
The date and time that the subscription was created. The value is specified in ISO 8601
(YYYY-MM-DDThh:mm:ss.sZ) format.
You can try the try this section from the documentation and check your Youtube Subscibers List using Creator Studio by following the steps here.
Note: The list only shows subscribers who have chosen to make their
subscriptions public. When a user first joins YouTube, their
subscriptions list is set to private by default.
Yes, here's an example in Python
import requests
headers = {
'Authorization': 'Bearer {0}'.format(token),
'Client-Id': client_id
}
query = {
'part': 'subscriberSnippet,snippet',
'mySubscribers': 'true',
'key': youtube_key
}
if cursor is not None:
query['pageToken'] = cursor
response = requests.get(
'https://youtube.googleapis.com/youtube/v3/subscriptions',
headers=headers, params=query)
res = response.json()
weirdly, snippet contains your authenticated user channel description and title but publishedAt field corresponds to when the item from subscriberSnippet subscribed to your authenticated user
I'm trying to figure out the best way to get a channel's upload playlistID given the channel's channelID. E.g. for the channel with channelID
UC9CuvdOVfMPvKCiwdGKL3cQ
The corresponding upload playlistID is
UU9CuvdOVfMPvKCiwdGKL3cQ
Notice the second character has changed from a "C" to a "U"
I can do this transformation via string manipulation, but I'm curious if there's a better, less hacky way to find the upload playlist ID through the official youtube api.
Here's some Kotlin code that shows my issue:
I can find the ChannelID for the "Game Grumps" channel through the following youtube api v3 search:
val req = youtube.search().list("snippet");
req.key = {API_KEY}
req.q = "Game Grumps"
req.type = "channel"
val response = req.execute();
The resulting Channel id (response.items[0].snippet.channelId) is UC9CuvdOVfMPvKCiwdGKL3cQ
But when I run the following to try to get the videos uploaded by the channel, I have to use the transformed ChannelID (starting with UU instead of UC)
val req = youtube.PlaylistItems().list("snippet")
req.playlistId = "UU9CuvdOVfMPvKCiwdGKL3cQ"
req.key = {API_KEY}
val response = req .execute()
If I use the untransformed "UC" channelID, I get the following error: The playlist identified with the requests playlistId parameter cannot be found.
Instead of just replacing the second character with a "U", what's the more robust way (e.g. using the youtube API) of translating a ChannelID to a PlaylistID (for the uploads from that channel)?
I would suggest using the official Youtube API, instead of trying to manipulate the strings. You can follow the instructions here:
Instructions to get video ids for all uploaded videos for a channel in V3
Get the channel id for the channel you want (you probably only need to do this once, then you can save it)
Use search.list
Set type to channel
Set q to the name of the channel you want
Grab the channel id (something like this: "channelId": "UC0X2VuXXXXXXXXXXXXXXXX")
Get the playlist id for the channel uploads using the channel id from step 1 (you probably only need to do this once, then you can save it)
Use channels.list
Set id to UC0X2VuXXXXXXXXXXXXXXXX from step 1
Grab the uploads key from contentDetails (something like this: "uploads": "UU0XXXXXXXXXXXXXXXXXXXX")
Get the videos via the playlistitems in the playlist using the playlist id from step 2
Use playlistItems.list
Set playlistId to UU0XXXXXXXXXXXXXXXXXXXX from step 2
Go through each PlaylistItem and pull out the video id
Im trying to get username given the channel ID but the only thing that i get is channel title from snippet and this is not always the same. For instance:
Channel ID: UC2OTNzQ5tsg2eSf-D2mMJ8Q
Channel Title: ▂▃▅▆ Gmanlens29 ▆▅▃▂
User Name: Gmanlens29
Channel ID: UCgG6-eQtPhAdr3GxYEN0HJw
Channel Title: ►►Edvisss◄◄
User Name: Edwin01230
Is there a way to make this?
Thank you in advance,
I think you'll need to link up with the google+ api, use status.isLinked for checking if a channel ID is linked to google+ and contentDetails.googlePlusUserId to snag it.
The channel resource's contentDetails.googlePlusUserId property has been deprecated. Previously, the property was only present if the channel was associated with a Google+ profile. Following the deprecation, the property will no longer be included in any channel resources.
I am using Zend's gdata library for the Google Apps provisioning API. Since Zend doesn't yet support fetching org users (no retrieve function provided by the library for this feed), I am making a custom gdata query to the url (as suggested in the documentation developers.google.com/google-apps/provisioning/#retrieving_organization_users_experimental):
apps-apis.google.com/a/feeds/orguser/2.0/'.$customerId.'?get=all
This works well for <= 100 users.
Now, I have created a domain with 125 users across 5 OUs. When I fetch the above URI, I get the 1st 100 users (as documented and expected). However, I could not find the pagination link mentioned here: developers.google.com/google-apps/provisioning/reference#Results_Pagination
Here's the start of my orguser feed:
<?xml version='1.0' encoding='UTF-8'?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:apps='http://schemas.google.com/apps/2006'><id>https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxxxx</id><updated>2013-01-06T08:17:43.520Z</updated><**link rel='next' type='application/atom+xml' href='https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxxxx?get=all&startKey=RASS03jtnz0s2orxmbn.**'/><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxx'/>
I tried the https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxxxx?get=all&startKey=RASS03jtnz0s2orxmbn. link but it gives me the exact same 100 users that the https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxxxx?get=all link gives. This is the only occurrence of the word "next" in my feed and so there is not other URI I can try to fetch the next 25 users.
So I have only been able to get 100 users from this API call. How do I go about fetching the next 25 users? Examples/code would be really appreciated. Or what am I doing wrong?
Please help - this is blocking an urgent delivery.
Thanks!,
Vinay.
Your 2nd request should look like:
https://apps-apis.google.com/a/feeds/orguser/2.0/C00xxxxxx?startKey=RASS03jtnz0s2orxmbn&get=all
startKey should be set to the value of the next parameter and get should continue to be all for each page request.
Also, make sure the URL is decoded, if & is encoded as & in the request, then Google's servers will see all of all&startKey=RASS03jtnz0s2orxmbn as the value of get and it won't see a startKey parameter at all.
In Facebook's documentation it says you can find the ID from a URL, and that used to be the case. It doesn't appear to be true anymore.
This example is straight from Facebook's API Documentation:
--------------FACEBOOK DOCS---------------------
The "ids" query parameter also accepts URLs. This is useful for finding IDs of URLs in the Open Graph. For example: https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
But when you click on that link it gives you:
{
"http://www.imdb.com/title/tt0117500/": {
"id": "http://www.imdb.com/title/tt0117500/",
"shares": 18226,
"comments": 7
}
}
Which does NOT include the real Facebook ID for this example URL. If I go to the debugger and enter this URL I can find the ID, which is: 380728101301
So how can I find the ID without using the Open Graph Debugger? I need to be able to get IDs through the code on my site, and can't manually visit the debugger every time.. anyone know how to do this now?
Thanks very much!
There is one possibility with FQL:
SELECT url,site,id FROM object_url WHERE url = 'http://www.imdb.com/title/tt0117500';
https://developers.facebook.com/docs/reference/fql/