我们正在努力建设一个服务导出谷歌在我们的gsuite域驱动文件。谷歌的API的PHP客户“错误”:“unauthorized_client”
我们正在与https://github.com/google/google-api-php-client
工作我们做了一个服务用户,下载并保存用户凭据,并授予域范围,对服务的访问用户。
中包含最简单的例子(如在每个文档,我发现):
putenv('GOOGLE_APPLICATION_CREDENTIALS='/service-account-credentials.json');
$client = new \Google_Client();
$client->setAuthConfig('service-account-credentials.json');
$client->setScopes('https://www.googleapis.com/auth/drive.file');
$client->useApplicationDefaultCredentials();
$client->setSubject('[email protected]');
$service = new \Google_Service_Drive($client);
$service->files->listFiles();
只要我们包括$client->setSubject('[email protected]');
它丢弃以下错误行:
{
"error": "unauthorized_client",
"error_description": "Client is unauthorized to retrieve access tokens using this method."
}
有没有人一个想法,或者可以共享此问题的代码示例。这是一个真正阻滞剂对我们和现在为什么这个错误出现
可能只是一个错字复制在这里也许,但你的第一和第三行均缺少引号让你的琴弦都搞砸了。 – Pacio
THX,但这只是错别字这里计算器 – vanBrunneren
您可以使用此[主题]参见(http://stackoverflow.com/questions/42067338/client-is-unauthorized-to-retrieve-access-tokens-using-this -方法)。你的错误意味着你的验证有问题。请仔细检查您是否[授予服务帐户访问权限](https://developers.google.com/api-client-library/php/auth/service-accounts#delegatingauthority)。您创建的服务帐户需要被授予对您想访问的用户数据的访问权限。 – abielita