【发布时间】:2016-06-19 03:45:33
【问题描述】:
我不完全确定如何描述标题,但我正在创建一个 API 来检索有关某个人的 Youtube 频道的特定 JSON 日期,并且在我遇到这样的频道之前,它工作得很好而且很花哨, https://www.youtube.com/channel/UCRMZyEp0IzcI0IGpDFRh6fQ
他的帐户 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();
}
【问题讨论】:
标签: php api youtube youtube-api