我并不完全知道如何标题,但是我创建了一个API来检索关于某人的Youtube频道的某个JSON日期,并且它工作正常,并且直到我遇到一个这样的频道, https://www.youtube.com/channel/UCRMZyEp0IzcI0IGpDFRh6fQ获取没有显示名称的YouTube频道ID
他的账号是在url中而不是 https://www.youtube.com/user/iceycat25。
当我运行API并搜索“iceycat25”时,数据被正常拖拉,但是如果我搜索“MOTO TIME”,则API不会返回此类用户。有没有什么办法解决这一问题? 下面是我现在的相关代码。
// obtain your own API key at
// https://console.developers.google.com
$MyKey = xxxxxxxxxx_xxxxxxxxxx_xxxxxxxxxx;
// Convert the GET data into variables.
$YoutubeName = $_GET["Channel_Name"];
$Command = $_GET["Command"];
// Get the channel ID and Upload ID from the YouTube name inputted
$IDs = json_decode(@file_get_contents("https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=$YoutubeName&key=$MyKey"), true);
if($IDs['items'][0]['id'] == null)
{
echo 'No such YouTube channel exists.';
die();
}
是的,似乎是这样。 https://developers.google.com/youtube/v3/guides/working_with_channel_ids – Alpix
如果我只是使用'id = $ YoutubeName'而不是'forUsername = $ YoutubeName',当我搜索“iceycat25”或“MOTO TIME” 。这要求我事先知道频道ID。回顾最终用户提供他们自己的渠道ID的情况会更好,因为显示名称不是唯一的,他们可能会为错误的用户提取数据。我只是把这个接受了。感谢您的帮助! –