我不太确定标题的措辞,但我正在创建一个 API 来检索关于某个人的 Youtube channel 的某些 JSON 日期,并且它工作正常而且花花公子,直到我遇到这样的 channel , 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();
}
最佳答案
我在我的论坛中将其作为 div
实现。
正如您在此处看到的,YouTube API 不接受同一参数中的用户名和 ID。
带身份证:
<div class="g-ytsubscribe" data-***channelid***="CHANNELID" data-layout="full" data-count="default"></div>
用户名:
<div class="g-ytsubscribe" data-***channel***="{$user.customFields.youtube_us}" data-layout="full" data-count="default"></div>
您必须更改属性。
只需使用 https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=$YoutubeName&key=$MyKey
试试,它应该可以,如果不行 - 请发表评论.
更多:https://developers.google.com/youtube/v3/docs/channels/list#examples
关于php - 获取没有显示名称的 youtube channel ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35812456/