【问题标题】:Obtain youtube channel id without display name获取不带显示名称的 youtube 频道 ID
【发布时间】: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


    【解决方案1】:

    我在我的论坛中以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&amp;id=$YoutubeName&amp;key=$MyKey 试试,它应该可以工作,如果没有 - 发表评论。

    更多:https://developers.google.com/youtube/v3/docs/channels/list#examples

    【讨论】:

    • 是的,看起来是这样。 developers.google.com/youtube/v3/guides/…
    • 如果我只使用id=$YoutubeName 而不是forUsername=$YoutubeName,当我搜索“iceycat25”或“MOTO TIME”时,什么都不会出现。这要求我事先知道频道 ID。回想起来,让最终用户提供他们自己的频道 ID 更好,因为显示名称不是唯一的,他们可能会为错误的用户提取数据。我只会将此标记为已接受。感谢您的帮助!
    猜你喜欢
    • 2020-11-26
    • 2014-08-16
    • 2014-11-17
    • 2018-04-16
    • 2017-04-10
    • 2013-07-22
    • 2014-10-12
    • 1970-01-01
    • 2015-06-23
    相关资源
    最近更新 更多