如何使用 YouTube API 获取频道名称?
Posted
技术标签:
【中文标题】如何使用 YouTube API 获取频道名称?【英文标题】:How to get channel name using YouTube API? 【发布时间】:2018-10-28 22:23:29 【问题描述】:我想获取视频的频道名称,但它给出了播放列表的名称。我目前正在使用这个网址var urlString = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&pageToken=\(pageToken)&playlistId=PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI&key=\(apiKey)"
它现在给了我这样的东西。
["items": <__NSArrayI 0x1c0472540>(
etag = "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/Vq7FiiHfUpgAr9yq9YxmBXwSLrE\"";
id = UExGZ3F1TG5MNTlhbENsXzJUUXZPaUQ1VmdtMWhDYUdTSS4xNDU2QkYwRjk0NkZBOEVD;
kind = "youtube#playlistItem";
snippet =
channelId = "UC-9-kyTW8ZkZNDHQJ6FgpwQ";
channelTitle = Music;
description = "\U201cThis is America\U201d by Childish Gambino http://smarturl.it/TcIgA\nDirector: Hiro Murai\nProducer: Jason Cole of Doomsday with Ibra Ake and Fam Rothstein of Wolf + Rothstein\ntour tickets and merchandise available at childishgambino.com";
playlistId = "PLFgquLnL59alCl_2TQvOiD5Vgm1hCaGSI";
position = 0;
publishedAt = "2018-05-18T11:29:31.000Z";
resourceId =
kind = "youtube#video";
videoId = VYOjWnS4cMY;
;
thumbnails =
default =
height = 90;
url = "https://i.ytimg.com/vi/VYOjWnS4cMY/default.jpg";
width = 120;
;
high =
height = 360;
url = "https://i.ytimg.com/vi/VYOjWnS4cMY/hqdefault.jpg";
width = 480;
;
maxres =
height = 720;
url = "https://i.ytimg.com/vi/VYOjWnS4cMY/maxresdefault.jpg";
width = 1280;
;
medium =
height = 180;
url = "https://i.ytimg.com/vi/VYOjWnS4cMY/mqdefault.jpg";
width = 320;
;
standard =
height = 480;
url = "https://i.ytimg.com/vi/VYOjWnS4cMY/sddefault.jpg";
width = 640;
;
;
title = "Childish Gambino - This Is America (Official Video)";
;
,
如您所见,channelTitle 是“音乐”。我怎样才能得到那个真正的频道标题?
【问题讨论】:
【参考方案1】:从任何播放列表或视频中获取频道 ID,并使用频道 ID 和 part='snippet'
创建一个 Channels:list API call。结果将包含频道标题和其他详细信息。
示例网址:https://www.googleapis.com/youtube/v3/channels?id=UC_x5XG1OV2P6uZZ5FSM9Ttw&part=snippet&key=API_KEY
回复:
"kind": "youtube#channelListResponse",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/3xuQp_Bnwrc1tW3bBIDi6LxzB7I\"",
"pageInfo":
"totalResults": 1,
"resultsPerPage": 1
,
"items": [
"kind": "youtube#channel",
"etag": "\"DuHzAJ-eQIiCIp7p4ldoVcVAOeY/czbu6JihYqowBUI2jn5-PBL7TvY\"",
"id": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"snippet":
"title": "Google Developers",
"description": "The Google Developers channel features talks from events, educational series, best practices, tips, and the latest updates across our products and platforms.",
"customUrl": "GoogleDevelopers",
"publishedAt": "2007-08-23T00:34:43.000Z",
"thumbnails":
"default":
"url": "https://yt3.ggpht.com/a-/AJLlDp2JcYTd7j-M2CUsBC2zO-p6TVYo0bE8dsS_fw=s88-mo-c-c0xffffffff-rj-k-no",
"width": 88,
"height": 88
,
"medium":
"url": "https://yt3.ggpht.com/a-/AJLlDp2JcYTd7j-M2CUsBC2zO-p6TVYo0bE8dsS_fw=s240-mo-c-c0xffffffff-rj-k-no",
"width": 240,
"height": 240
,
"high":
"url": "https://yt3.ggpht.com/a-/AJLlDp2JcYTd7j-M2CUsBC2zO-p6TVYo0bE8dsS_fw=s800-mo-c-c0xffffffff-rj-k-no",
"width": 800,
"height": 800
,
"localized":
"title": "Google Developers",
"description": "The Google Developers channel features talks from events, educational series, best practices, tips, and the latest updates across our products and platforms."
]
【讨论】:
以上是关于如何使用 YouTube API 获取频道名称?的主要内容,如果未能解决你的问题,请参考以下文章
使用 YouTube API,如何从频道名称中获取直播的视频 ID?
如何使用他们的 API 获取 YouTube 中频道的 ID、名称和所有统计信息