【问题标题】:What scope is required to access a YouTube channel title through an access token?通过访问令牌访问 YouTube 频道标题需要什么范围?
【发布时间】:2017-10-25 17:11:11
【问题描述】:

我正在开发一个使用 Google 的 PHP API 库的项目。我目前正在使用具有offline 访问权限的范围:

  • https://www.googleapis.com/auth/youtube.force-ssl
  • https://www.googleapis.com/auth/youtube.upload

但这并没有让我获得获取已验证频道的频道标题的权限。

然后我尝试添加更多范围:

  • https://www.googleapis.com/auth/youtube.readonly
  • https://www.googleapis.com/auth/youtubepartner
  • https://www.googleapis.com/auth/youtubepartner-channel-audit

但我也有同样的结果。是否有一个与 YouTube 无关的范围,但我错过了?

-

这是我正在使用的代码,注意$this->clientGoogle_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


    【解决方案1】:

    别忘了添加这个scope

    https://www.googleapis.com/auth/youtube
    

    以及snippet下的字段参数'title'。

    这是我的使用 API explorer

    "title": "Steve Jobs" //that's my title
    

    【讨论】:

    • 我认为 force SSL 范围与 just YouTube 范围相同。我会调查这个
    • 包括两个范围
    猜你喜欢
    • 1970-01-01
    • 2016-10-06
    • 2016-10-22
    • 2023-02-10
    • 2020-10-05
    • 2016-09-18
    • 2013-03-20
    • 2017-01-18
    • 1970-01-01
    相关资源
    最近更新 更多