gpt4 book ai didi

google-api - Google API 服务帐户授权错误

转载 作者:行者123 更新时间:2023-12-04 12:52:08 29 4
gpt4 key购买 nike

我正在使用 google-api-php-client客户端使用服务帐户连接到 Google Drive。大多数时候它都有效,但每隔一段时间(比如我坐在这里一遍又一遍地刷新页面,它是每 5 到 10 次),我会收到 Google_Service_Exception留言 unauthorized_client: Client is unauthorized to retrieve access tokens using this method .该错误仅在 $this->drive_service->files->listFiles() 时发生代码存在。如果我直接使用服务帐户而不是使用 setSubject(),则不会发生这种情况。冒充另一个用户。

        $this->client = new Google_Client();
$this->client->useApplicationDefaultCredentials();
$this->client->addScope("https://www.googleapis.com/auth/drive");
$this->client->setSubject('xxxx');
$this->drive_service = new Google_Service_Drive($this->client);
$files = $this->drive_service->files->listFiles();

有什么想法吗?

2017 年 2 月 21 日更新:该错误不再是间歇性的,每次都会发生,因此我根本无法再通过服务帐户连接到常规帐户。

2017 年 3 月 10 日更新:这似乎是用户的误解。服务帐户必须被授予“域范围的权限”才能模拟该域的用户——这是我没有做过的事情。我只是按照 here 所述授权客户访问用户帐户.

最佳答案

我不知道为什么您的错误会定期发生,但我的理解是要冒充用户,您必须 grant the service account access .

关于google-api - Google API 服务帐户授权错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41903578/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com