我正在使用 Google PHP 客户端访问电子表格数据。
我收到这个 fatal error :
Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "code": 403, "message": "The caller does not have permission", "errors": [ { "message": "The caller does not have permission", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }
我的代码:
$client = new Google_Client();
$client->setApplicationName("Google spreadsheets");
$client->setDeveloperKey("xxxxx");
$client->setScopes(array('https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets.readonly',
'https://www.googleapis.com/auth/drive.file'));
$service = new Google_Service_Sheets($client);
$range = 'Class Data!A2:E';
$response = $service->spreadsheets_values->get($sheetid, $range);
$values = $response->getValues();
if (count($values) == 0) {
print "No data found.\n";
} else {
print "Name, Major:\n";
foreach ($values as $row) {
// Print columns A and E, which correspond to indices 0 and 4.
printf("%s, %s\n", $row[0], $row[4]);
}
}
如何解决这个问题?
最佳答案
获取服务帐户电子邮件地址,并像与任何其他用户一样与其共享工作表。然后它将可以访问工作表
关于php - Google Api Php 客户端 - 电子表格权限错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44585903/