2 Answers

1
votes

when I search for a channel by ID .. I get no items returned.

Give the Try-it section for channels.list a try. I'm able to fetch JSON response by using these parameters:

 part->contentDetails
 id-> yourchannel ID

Authorize and Execute

The response it returned is not empty at all.

{
 "kind": "youtube#channelListResponse",
 "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/FiuYcDu7WFmoFVcLDRvENYGl_tQ\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {

   "kind": "youtube#channel",
   "etag": "\"I_8xdZu766_FSaexEaDXTIfEWc0/QjMybH99xT3x-znrh2Yerx_0DWk\"",
   "id": "{my channel id}",
   "snippet": {
    "title": "{my channel name}",
    "description": "",
    "publishedAt": "2011-10-10T15:30:40.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-EN5H1HDHqIU/ABCDEFGHIJK/ABCDEFGHIJK/l2gqeYg94P8/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "{my channel name}",
     "description": ""
    }
   }
  }
 ]
}

That's a lot of results for me.

But when I search by userName, it returns the channel ID that I just searched for.

In the channels.list try-it docs above, forUsername is defined as the forUsername parameter specifies a YouTube username, thereby requesting the channel associated with that username. So I think it's doing it's job.

Additional note on forUsername parameter is that's it's used to translate your arbitrary legacy YouTube username, that's the old Youtube accounts, into a channel ID using v3 of the API. More of that in Work with Channel IDs guide.

1
votes

when I search by userName, it returns the channel ID that I just searched for

You miss the important part to search by forUsername or channelID. That is snippet part, not contentDetails.

by forUsername :

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

by id channel:

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

That will exactly returned to like below:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/VnicD0AYsCI7KlKKcdsmdIlWUMs\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/Nl4tuuOFwuPOdHmP_Ky3vuIQ2Gg\"",
   "id": "UC_pwIXKXNm5KGhdEVzmY60A",
   "snippet": {
    "title": "CJENMMUSIC Official", <== Channel Name
    "description": "Asia's No.1 Entertainment & Media Company", <== Channel Desctiption
    "customUrl": "cjenmmusic", <=== Channel URL who has been qualified - to and for - claimed it
    "publishedAt": "2011-03-25T04:48:40.000Z",
    "thumbnails": {
     "default": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "medium": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     },
     "high": {
      "url": "https://yt3.ggpht.com/-QMkGdFbhrOc/AAAAAAAAAAI/AAAAAAAAAAA/6boUKax-3EA/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
     }
    },
    "localized": {
     "title": "CJENMMUSIC Official",
     "description": "Asia's No.1 Entertainment & Media Company"
    }
   }
  }
 ]
}

While if you just pointing to contentDetails, it will return to almost nothing:

{
 "kind": "youtube#channelListResponse",
 "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/C7SnOhT2c-Fs2R9f6JlxlOPWc34\"",
 "pageInfo": {
  "totalResults": 1,
  "resultsPerPage": 1
 },
 "items": [
  {
   "kind": "youtube#channel",
   "etag": "\"uQc-MPTsstrHkQcRXL3IWLmeNsM/3RTKaEQC9GX8c58R2Bhd8G1y3zM\"",
   "id": "UC_pwIXKXNm5KGhdEVzmY60A",
   "contentDetails": { <============== detail contents
    "relatedPlaylists": {
     "uploads": "UU_pwIXKXNm5KGhdEVzmY60A",
     "watchHistory": "HL",
     "watchLater": "WL"
    }
   }
  }
 ]
}