【发布时间】:2018-07-02 06:25:37
【问题描述】:
之后我收到以下错误:
致命错误:未捕获的 Google_Service_Exception: { "error": "unauthorized_client", "error_description": "客户端未经授权无法使用此方法检索访问令牌。" }
对于谷歌管理员设置,我们关注此链接: https://developers.google.com/api-client-library/php/auth/service-accounts
我们正在使用restapi.php
require __DIR__ . '/vendor/autoload.php';
/**
* Returns an authorized API client.
* @return Google_Client the authorized client object
*/
putenv('GOOGLE_APPLICATION_CREDENTIALS=client_secret.json');
$client = new Google_Client();
$client->setApplicationName('rwmp');
$client->setAccessType("offline"); // offline access
$client->useApplicationDefaultCredentials();
$client->setSubject('user@myconference.center');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$service = new Google_Service_Sheets( $client );
$spreadsheetId = '1WtuEXGm8oWxet6t9UcPU-mi7lgif1sqeTcmc9DO-_zs';
$range = 'A:G';
$response = $service->spreadsheets_values->get($spreadsheetId,$range);
$values = $response->getValues();
(a) 我们使用的是 G-Suite“基础版”;那有什么限制吗? (b) 我们从 PHP (7.0) 环境调用 G-Suite API;由于环境仍标记为“(Beta)”,因此是否存在任何已知问题。 (c) 是否有任何示例/教程可以指导解决我们的问题。
【问题讨论】:
标签: php google-sheets google-api google-drive-api service-accounts