如何通过 YouTube 数据 API V3 端点搜索通过频道 ID 获取频道图标

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

我在 /search enpoint 上发出请求:https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UC8M5YVWQan_3Elm-URehz9w&key=AIzaSyAp8yGkCqT9e9p7IzgpE24KGoqLRgNhOg0&q=Utopia

我收到了视频及其预览,但频道图标没有出现,我阅读了如何获取频道图标,我明白了,https://developers.google.com/youtube/v3/docs/search/list你需要什么才能从 Id 中获取 channelId class 并将其传递给 channelId 查询参数,之后有关频道的数据将进入 Snippet 模型,图标将进入缩略图,但我不明白如何以及从何处从模型 ID 获取 channelId 以及在哪里它被传递给请求参数,最好从哪里得到它?

频道图标,你是指频道头像? - 如果是,那么,是的,频道图标 出现在响应的 youtube#channel 中。

这是您使用 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": "Клоунада и театральщина Реклама: utopia@tag.show #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]
  ]
}

您可以从此回复中获得频道图标,如下所示:

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

您将获得:

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

其中 JSON_response 是请求的响应。我不确定您是如何阅读回复中的项目的,但是,我希望这个回答对您有所帮助。