Home > database >  How to get channel icon by channelId with enpoint search from YouTube Data API V3
How to get channel icon by channelId with enpoint search from YouTube Data API V3

Time:11-21

I make a request on /search enpoint: https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC8M5YVWQan_3Elm-URehz9w&key=AIzaSyAp8yGkCqT9e9p7IzgpE24KGoqLRgNhOg0&q=Utopia

I receive videos and their previews, but the channel icon is not coming, and I read how you can get the channel icon, there I understood, https://developers.google.com/youtube/v3/docs/search/list what you need to get channelId from the Id class and pass its to channelId query parameter, after which data about the channel will come to the Snippet model, and the icon to Thumbnails, but I don't understand how and where to get the channelId from the model Id and where it is passed to the request parameter, where it is better to get it his ?

CodePudding user response:

By channel icon, you mean the channel profile picture? - if so, then, yes, the channel icon appears in the youtube#channel of the response.

This is part of the response you receive by using your sample request:

{
  "kind": "youtube#searchListResponse",
  "etag": "hwZ_cPPePXCDt8h44C-3Ym9NP2I",
  "nextPageToken": "CAUQAA",
  "regionCode": "CO",
  "pageInfo": {
    "totalResults": 244,
    "resultsPerPage": 5
  },
  "items": [
    {
      "kind": "youtube#searchResult",
      "etag": "p0M_r8_zUEtBcT7MrX49-24RkXU",
      "id": {
        "kind": "youtube#channel",
        "channelId": "UC8M5YVWQan_3Elm-URehz9w"
      },
      "snippet": {
        "publishedAt": "2015-04-14T02:57:14Z",
        "channelId": "UC8M5YVWQan_3Elm-URehz9w",
        "title": "Utopia Show",
        "description": "Клоунада и театральщина Реклама: [email protected] #utopia_show #topatella #topsecret.",
        "thumbnails": {
          "default": {
            "url": "https://yt3.ggpht.com/ytc/AKedOLRf5WOTI2S1ruF-YWz22VFqh5QxpMEZiqWX5vDWTw=s88-c-k-c0xffffffff-no-rj-mo"
          },
          "medium": {
            "url": "https://yt3.ggpht.com/ytc/AKedOLRf5WOTI2S1ruF-YWz22VFqh5QxpMEZiqWX5vDWTw=s240-c-k-c0xffffffff-no-rj-mo"
          },
          "high": {
            "url": "https://yt3.ggpht.com/ytc/AKedOLRf5WOTI2S1ruF-YWz22VFqh5QxpMEZiqWX5vDWTw=s800-c-k-c0xffffffff-no-rj-mo"
          }
        },
        "channelTitle": "Utopia Show",
        "liveBroadcastContent": "none",
        "publishTime": "2015-04-14T02:57:14Z"
      }
    },
    {
      "kind": "youtube#searchResult",
      "etag": "0JhSluN0BMHidIIoDBC19t7HNik",
      "id": {
        "kind": "youtube#video",
        "videoId": "Ywpd8M6wfHc"
      },
      "snippet": {
        "publishedAt": "2021-10-05T13:43:17Z",
        "channelId": "UC8M5YVWQan_3Elm-URehz9w",
        "title": "ТЫ БЫ НИКОГДА ТАКОЕ НЕ ЗАГУГЛИЛ #9",
        "description": "https://go.skyeng.ru/utopia_show_skypro - Начни свой путь в IT с онлайн-университетом Skypro. Забирай 10% скидку на один из курсов по промокоду ...",
        "thumbnails": {
          "default": {
            "url": "https://i.ytimg.com/vi/Ywpd8M6wfHc/default.jpg",
            "width": 120,
            "height": 90
          },
          "medium": {
            "url": "https://i.ytimg.com/vi/Ywpd8M6wfHc/mqdefault.jpg",
            "width": 320,
            "height": 180
          },
          "high": {
            "url": "https://i.ytimg.com/vi/Ywpd8M6wfHc/hqdefault.jpg",
            "width": 480,
            "height": 360
          }
        },
        "channelTitle": "Utopia Show",
        "liveBroadcastContent": "none",
        "publishTime": "2021-10-05T13:43:17Z"
      }
    },
    [other videos items here]
  ]
}

You can get from this response the channel icon as follows:

JSON_response.items[0].snippet.thumbnails.medium.url

You will get:

https://yt3.ggpht.com/ytc/AKedOLRf5WOTI2S1ruF-YWz22VFqh5QxpMEZiqWX5vDWTw=s240-c-k-c0xffffffff-no-rj-mo

Where JSON_response is the response of the request. I'm not sure how you're reading the items in the response, but, I hope this answer helps you.

  • Related