Reputation: 2374
I want to replace a vanity name (like "thejntest") with the corresponding user-id (UCWLptbzZ....) programmatically. I don't find any possibility within the Channels-List call
After searching here on stackoverflow, I found the following thread (Retrieve Youtube Channel info for "Vanity" channel), where the usage of the Search-List call is described. Although it's a good idea to search youtube for a given username and contenttype = "channel", I don't received satisfying results at all. (sometimes there are too many results)
So I was wondering if there's another possibility to get a user-id based on the username? Or is it safe to rely on the first result of the search query, or by double checking wether a returned username corresponds to the given search-query?
Upvotes: 2
Views: 10690
Reputation: 357
I know the answer is 1 year later but in the V3 of the youtube API you can call with channel id (param id
) OR user name (param forUsername
)
Example for user name :
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2Cstatistics%2CcontentDetails%2CtopicDetails&forUsername=KarlWolfVEVO&key={YOUR_API_KEY}
Example for channel id :
https://www.googleapis.com/youtube/v3/channels?part=id%2Csnippet%2Cstatistics%2CcontentDetails%2CtopicDetails&id=UC8FAXi_Vb4kDocI1UrH_sKQ&key={YOUR_API_KEY}
Upvotes: 9
Reputation: 5317
I agree that it seems counterintuitive, but I've been assured through the Youtube Developer Relations Team that the first result of a Search method for a given channel name will always return the correct channel item (and id).
Make sure you keep type = "channel" in your search, and you can limit the result set to 1 by including "maxResults=1" in your call.
For example, the following call:
https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&maxResults=1&q=thejntest&type=channel&key={YOUR_API_KEY}
returns:
{
"kind": "youtube#searchListResponse",
"etag": "\"4IfXb8Dc78bqDKapqHxgOpqGpzM/lKqCVcHLORctmp6mp9sgSil_W0w\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"4IfXb8Dc78bqDKapqHxgOpqGpzM/UoEAOMl45xX5SIWjDGxyS-74WKE\"",
"id": {
"kind": "youtube#channel",
"channelId": "UCWLptbzZMaxQ7doUzgjMg_A"
},
"snippet": {
"publishedAt": "2013-04-23T08:28:54.000Z",
"channelId": "UCWLptbzZMaxQ7doUzgjMg_A",
"title": "TheJNtest",
"description": "What a wonderful testing world it is!",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/i/WLptbzZMaxQ7doUzgjMg_A/1.jpg"
},
"medium": {
"url": "https://i.ytimg.com/i/WLptbzZMaxQ7doUzgjMg_A/mq1.jpg"
},
"high": {
"url": "https://i.ytimg.com/i/WLptbzZMaxQ7doUzgjMg_A/hq1.jpg"
}
},
"channelTitle": "TheJNtest"
}
}
]
}
where "UCWLptbzZMaxQ7doUzgjMg_A" is your channelId.
Upvotes: 3