我並不完全知道如何標題,但是我創建了一個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的情況會更好,因爲顯示名稱不是唯一的,他們可能會爲錯誤的用戶提取數據。我只是把這個接受了。感謝您的幫助! –