【发布时间】:2017-10-25 17:11:11
【问题描述】:
我正在开发一个使用 Google 的 PHP API 库的项目。我目前正在使用具有offline 访问权限的范围:
https://www.googleapis.com/auth/youtube.force-sslhttps://www.googleapis.com/auth/youtube.upload
但这并没有让我获得获取已验证频道的频道标题的权限。
然后我尝试添加更多范围:
https://www.googleapis.com/auth/youtube.readonlyhttps://www.googleapis.com/auth/youtubepartnerhttps://www.googleapis.com/auth/youtubepartner-channel-audit
但我也有同样的结果。是否有一个与 YouTube 无关的范围,但我错过了?
-
这是我正在使用的代码,注意$this->client 是Google_Client 的一个实例:
/**
* Fetch channel title
*
* @return string
*/
public function fetchChannelTitle() {
/** @var \Google_Service_YouTube_Channel $details */
$details = $this->getChannelDetails();
$snippet = $details->getSnippet();
return $snippet->getTitle();
}
/**
* Get channel details
*
* @throws YouTubeException
*/
public function getChannelDetails()
{
if (!$this->access_token) {
throw new YouTubeException('NO_REFRESH_TOKEN');
}
$this->client->setAccessToken($this->access_token);
$parts = 'snippet,contentDetails,statistics';
$params = ['mine' => true];
$response = (new Google_Service_YouTube($this->client))->channels->listChannels(
$parts,
$params
);
return $response->getItems()[0];
}
【问题讨论】:
标签: youtube google-api youtube-api