获取不带显示名称的 youtube 频道 ID


Obtain youtube channel id without display name

我不确定如何措辞标题,但我正在创建一个 API 来检索有关个人 Youtube 频道的某些 JSON 日期,它工作正常且花花公子,直到我遇到这样的频道, https://www.youtube.com/channel/UCRMZyEp0IzcI0IGpDFRh6fQ

他的账户 ID 在网址中,而不是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