php - 获取没有显示名称的 youtube channel ID

标签 php api youtube youtube-api

我不太确定标题的措辞,但我正在创建一个 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/

相关文章:

php - 在 PHP 中使用 DOMDocument 的正则表达式

flash - 关于在表单上的Flash Player中播放youtube电影的 ActionScript

javascript - 更改输入值时如何重置表单的输入值?

api - 检索对开放图 2 中的自定义对象执行自定义操作的好友列表

ios - MPMoviePlayerController 正在播放 YouTube 视频吗?

javascript - YouTube API和javascript问题

php - MySQL标签搜索

php - 使用 php 从多个 mysql 表中获取并显示值

php - 选项国家html与mysql

json - 如何过滤 API 响应以在 Swift 中包含/排除 TableView 中的一些数据