2

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?

Community
  • 1
  • 1
Johannes N.
  • 2,364
  • 3
  • 28
  • 45

2 Answers2

9

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}
Michele d'Amico
  • 22,111
  • 8
  • 69
  • 76
sym
  • 357
  • 4
  • 7
3

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.

Matt Koskela
  • 5,269
  • 3
  • 26
  • 29
  • 1
    Thx Matt for pointing this out, but I have an use case, where the mentioned method does not work: pls test https://developers.google.com/youtube/v3/docs/search/list with the "q" => "test" and "type" => "channel" - you will receive "motorvisiontest" as the first returned element :/ – Johannes N. Apr 24 '13 at 11:00
  • If you recheck the url response it now returns a single item of type video, any ideas what happened here? – nytrm Aug 06 '13 at 12:20
  • No idea - I would file a bug report, because the current response is unexpected. – Matt Koskela Aug 06 '13 at 19:43