googleworkspace / php-samples

PHP samples for Google Workspace APIs
Apache License 2.0
288 stars 347 forks source link

Uncaught Google_Service_Exception error code 400 FAILED_PRECONDITION #65

Open luckydevilru opened 4 years ago

luckydevilru commented 4 years ago

In one sheet its work fine. I try to get cells from another sheet document and it became impossible. I always get this errors, event try to do it from owner accont. Owner accaunt work fine with another sheet docs too.

Errors:

Warning: count(): Parameter must be an array or an object that implements Countable in /directory/import/Google/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 67

Warning: count(): Parameter must be an array or an object that implements Countable in /directory/import/Google/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php on line 67

Fatal error: Uncaught Google_Service_Exception: { "error": { "code": 400, "message": "This operation is not supported for this document", "errors": [ { "message": "This operation is not supported for this document", "domain": "global", "reason": "failedPrecondition" } ], "status": "FAILED_PRECONDITION" } } in /directory/import/Google/vendor/google/apiclient/src/Google/Http/REST.php:118 Stack trace: #0 /directory/import/Google/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'GoogleService...') #1 /directory/import/Google/vendor/google/apiclient/src/Google/Task/Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'GoogleService...') #2 /directory/import/Google/ven in /directory/import/Google/vendor/google/apiclient/src/Google/Http/REST.php on line 118

Sample: ` <?

ini_set('error_reporting', E_ALL); ini_set('display_errors', 1); ini_set('display_startup_errors', 1);

require_once DIR . '/Google/vendor/autoload.php'; $client = new \Google_Client(); $client->setApplicationName('Google sheet and PHP'); $client->setScopes([\Google_Service_Sheets::SPREADSHEETS_READONLY]); $client->setAccessType('offline'); // $client->setAuthConfig(DIR.'/EraVitex-ec458f567057.json'); $client->setAuthConfig(DIR.'/Eravitex-736c25228468.json'); #prokh.sergey $service = new Google_Service_Sheets($client); // var_dump($service); // $spreadsheetId = "1AUGdmO645L4n-mHH9vxgTAUmPG2vkhqmtay5-9w66Ak"; // $spreadsheetId = "1mKLemNR2VMDj_wE5crSiR11-mq8VrirVcjCAJ4Caq_k"; //-new $spreadsheetId = "1QrfFUFTsMNHTM3SPvD24_Y2WXM64WcdI";

// $range = "Ковщики!A1:B10"; $range = "TIU!A1:B10"; $response = $service->spreadsheets_values->get($spreadsheetId, $range); $values = $response->getValues(); if (empty($values)){ echo 'no data'; } else{ $mask ="%10s %-10s %s\n"; foreach ($values as $row){ echo $row[0].'-'.$row[1]."\n"; } }

?>`

Steps to Reproduce the Problem

  1. Tel me please how to solve this problems

Specifications

luckydevilru commented 4 years ago

I fogot to tell what if do with this guide https://developers.google.com/sheets/api/quickstart/php?hl=ru - I got the same mistakes.

Its may be becouse the document have more then one author?