PHP YouTube数据API无需宣誓即可获取频道信息
我想根据用户名或频道id提取频道信息。此信息来自用于查看该频道的URL 例:或 我有以下代码:PHP YouTube数据API无需宣誓即可获取频道信息,php,youtube,youtube-data-api,youtube-channels,Php,Youtube,Youtube Data Api,Youtube Channels,我想根据用户名或频道id提取频道信息。此信息来自用于查看该频道的URL 例:或 我有以下代码: $this->load->library('APIs/YouTube'); echo "["; echo json_encode($this->youtube->getId('channel/UCkklJA9WbtJM5-g21xHI3yA'),false); echo "\n]"; 调用的函数是: public function getId($url) { $id
$this->load->library('APIs/YouTube');
echo "[";
echo json_encode($this->youtube->getId('channel/UCkklJA9WbtJM5-g21xHI3yA'),false);
echo "\n]";
调用的函数是:
public function getId($url) {
$id = explode('/', $url);
echo json_encode($id).',';
//User's channel
if ($id[0] === 'user') {
$response = $this->youtube->channels->listChannels('id,snippet',array(
'forUsername' => $id[1]
));
}
//Channel id
else {
$response = $this->youtube->channels->listChannels('id,snippet',array(
'id' => $id[1],
'maxResults' => 2
));
}
return $response;
}
以下是youtube类的构造函数:
public function __construct()
{
$this->client = new Google_Client();
$this->client->setDeveloperKey($this->api_key);
$this->client->setClientId($this->client_id);
$this->client->setClientSecret($this->client_secret);
$this->client->setScopes(array(
Google_Service_Oauth2::PLUS_LOGIN,
Google_Service_Oauth2::PLUS_ME,
Google_Service_Oauth2::USERINFO_EMAIL,
Google_Service_Oauth2::USERINFO_PROFILE,
Google_Service_YouTube::YOUTUBE
));
$ci =& get_instance();
$this->client->setRedirectUri($ci->config->item('base_url').'auth/youtube/');
$this->oauth = new Google_Service_Oauth2($this->client);
$this->youtube = new Google_Service_YouTube($this->client);
}
使用“user/csga5000”调用函数也不起作用
结果如下:
[
[
"channel",
"UCkklJA9WbtJM5-g21xHI3yA"
],
{
"etag":"\"IHLB7Mi__JPvvG2zLQWAg8l36UU\/KcPrlZVHCJ9bAKurpGOj1BBEH6g\"",
"eventId":null,
"kind":"youtube#channelListResponse",
"nextPageToken":null,
"prevPageToken":null,
"visitorId":null
}
]
我只想要这样的结果:
{你的API密钥}
或
{你的API密钥}
您可以在此处进行测试:
用户名为csga5000或id为UCkklJA9WbtJM5-g21xHI3yA
我找到的所有示例都使用了“mine=>true”和oauth来加载这些数据,因此google上的任何内容或堆栈溢出似乎都没有帮助。我只是遗漏了一些愚蠢的东西,我对响应感到非常困惑 我需要电话:
$response->getItems();