我收到以下錯誤:谷歌電子表格API問題
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]);
}
}
誰能幫助/指導我找到問題的原因是什麼?
你試過的郵政編碼! – Thamaraiselvam
該消息告訴你什麼是錯誤的:'該請求缺少一個有效的API密鑰'。 –
CODE: $ 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「找不到數據。\ n」; } else { print「Name,Major:\ n」; ($ value爲$ row){printf(「%s,%s \ n」,$ row [0],$ row [4]); } } –