即使我使用Node.js,我仍在使用REST API Youtube v3.0 Data API
。
我只有YouTube频道的显示名称(例如Traversy Media
或Android Developers
),我只需要从其名称中获取频道ID。
现在,我正在使用他们的显示名称,只是希望它也是他们的用户名。我从那里得到他们的身份证。但是大多数渠道的显示名称与用户名不同。
https://www.googleapis.com/youtube/v3/channels?key=${config.key}&forUsername=${name}&part=id
这就是我目前正在检索ID的方式,但是就像我说的那样,用户名并不总是显示名称。
再次,我如何从显示名称中获取ID?
答案 0 :(得分:0)
为此,您必须使用api的Search部分,例如此调用
https://www.googleapis.com/youtube/v3/search?key={KEY}&part=snippet&type=channel&maxResults=1&q=traversy+media
您显然可以将KEY替换为从Google云控制台生成的API密钥。
上面的调用返回
{
"kind": "youtube#searchListResponse",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/TA3dq6AD2oajHPE0-0Y9hZzSmi8\"",
"nextPageToken": "CAEQAA",
"regionCode": "US",
"pageInfo": {
"totalResults": 34,
"resultsPerPage": 1
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"XpPGQXPnxQJhLgs6enD_n8JR4Qk/SJmA2ZkjStP6_YHYQcEsg9JrWz4\"",
"id": {
"kind": "youtube#channel",
"channelId": "UC29ju8bIPH5as8OGnQzwJyA"
},
"snippet": {
"publishedAt": "2009-10-30T21:33:14.000Z",
"channelId": "UC29ju8bIPH5as8OGnQzwJyA",
"title": "Traversy Media",
"description": "Traversy Media features the best online web development and programming tutorials for all of the latest web technologies including Node.js, Angular 2, React.js, ...",
"thumbnails": {
"default": {
"url": "https://yt3.ggpht.com/-OsgBxXITFdg/AAAAAAAAAAI/AAAAAAAAAAA/gDaUV_aSb2Q/s88-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"medium": {
"url": "https://yt3.ggpht.com/-OsgBxXITFdg/AAAAAAAAAAI/AAAAAAAAAAA/gDaUV_aSb2Q/s240-c-k-no-mo-rj-c0xffffff/photo.jpg"
},
"high": {
"url": "https://yt3.ggpht.com/-OsgBxXITFdg/AAAAAAAAAAI/AAAAAAAAAAA/gDaUV_aSb2Q/s800-c-k-no-mo-rj-c0xffffff/photo.jpg"
}
},
"channelTitle": "Traversy Media",
"liveBroadcastContent": "upcoming"
}
}
]
}