我收到以下错误:
Uncaught exception 'Google_Service_Exception' with message
{ "error": { "code": 403, "message": "The request is missing a valid API key.",
"errors": [ { "message": "The request is missing a valid API key.", "domain": "global",
"reason": "forbidden" } ],
"status": "PERMISSION_DENIED" }
}
我的代码是:
$client = new Google_Client();
$client->setAuthConfig('google-api-php-client-2.1.1/client_secret.json');
$client->addScope(Google_Service_Drive::DRIVE);
$client->setRedirectUri($redirect_uri);
$spreadsheetId = '1Ybwc_wNhvc6tVQIRY-33qwkY0WoGj09uIQ3YQqa9fvo';
$range = 'sample!A2:E'; $response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if (count($values) == 0) {
print "No data found.\n";
} else {
print "Name, Major:\n";
foreach ($values as $row) {
printf("%s, %s\n", $row[0], $row[4]);
}
}
任何人都可以帮助/指导我找到问题的原因吗?
答案 0 :(得分:0)
如果这是针对php客户端库的,请参阅 Using OAuth 2.0 for Web Server Applications有关启用API和获取代码凭据的信息。从该页面注释:
上述链接页面上的信息将指导您获取有效的API密钥。
答案 1 :(得分:0)
如果稍后更新应用程序范围,则必须重新进行身份验证并更新credentials.json。