0

Good Day, I Try to Get Channel ID using service account, because I´m using it on other scopes on my project. But when I do request process its give me the service account information. i´m using php btw

Many thanks in advance and any help will be appreciated.

p.d. i´m replace real account info for dummy text.

Channel id on the tab and results image

And of Course the code :

$credentials_file = $this->key_dir . $this->key_file['title'];

    $client = new \Google_Client();
    $client->setAuthConfig($credentials_file);
    $client->addScope('https://www.googleapis.com/auth/youtube');

    $client->setApplicationName("Youtube Analytics");
    $client->refreshTokenWithAssertion();

    $token = $client->getAccessToken();
    $accessToken = $token['access_token'];
    if (!empty($accessToken)) {

    $service = new \Google_Service_YouTube($client);

    $data = $service->channels->listChannels('id,snippet', array('mine' => 'true'));

    echo "id: " . $data->items[0]->id . "<br>";
    echo "Kind: " . $data->items[0]->kind . "<br>";
    echo "Snippet -> title : " . $data->items[0]->snippet['title'] . "<br>";

    }
4

1 回答 1

3

AFAIK,Youtube API 不支持服务帐户流程。如文档中所述:

服务帐户流支持不访问用户信息的服务器到服务器交互。但是,YouTube 数据 API 不支持此流程。由于无法将服务帐户链接到 YouTube 帐户,因此尝试使用此流程授权请求将产生NoLinkedYouTubeAccount错误。

同样在Youtube v3 Google 服务帐户访问问题中,“没有计划向 YouTube 数据 API v3 调用添加对服务帐户授权的支持。” 如相关的 SO 问题#21890982#21057358 所述:您需要自己的帐户,并且可以使用 V3 为服务创建身份验证,而无需用户干预。

希望这可以帮助。

于 2016-11-16T15:48:25.147 回答