first let me say i apologize if this is an easy solution, i’ve never used google api or anything similar, as well as i’m new to php
i’m currently trying to read a spreadsheet using google sheets api and just print it out. i think everything looks fine, but when i run it, it gives me this error:
PHP Fatal error: Uncaught GoogleServiceException: {
“error”: {
“code”: 404,
“message”: “Requested entity was not found.”,
“errors”: [
{
“message”: “Requested entity was not found.”,
“domain”: “global”,
“reason”: “notFound”
}
],
“status”: “NOT_FOUND”
}
}
here is my php file:
require __DIR__ . '/vendor/autoload.php';
$client = new Google_Client();
$client->setApplicationName('Sheets Test');
$client->setScopes([Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig(__DIR__ . '/credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheetId = "1sefMmSCVnQRMVFuG8l5SKx7phpD2vvmwzq7opsgyuebYIU";
$range = "currentRatings!A2:C4";
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
$values = $response->getValues();
if(empty($values)){
print "No data found. n";
} else {
$mask = "%10s %-10s $sn";
foreach($values as $row){
echo sprintf($mask, $row[2], $row[1], $row[0]);
}
}
as shown above, i did connect a credentials file which is the same service account that the sheet is shared to. i also know that the problem occurs/starts at this line:
$response = $service->spreadsheets_values->get($spreadsheetId, $range);
here’s what i’ve tried:
- double checking the sheet id
- downgrading the version of google api via composer
- changing the “$range” values (nothing changed, even when i changed the name of the sheet to an incorrect name)
- creating a new service account in google console
- making sure the sheet is shared to the service account
acar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.