1

GoogleシートAPIを使用してスプレッドシート(​​ID)からすべてのシートを取得しようとしました。 RESTメソッドが見つかりませんでした。Values.getから複数の範囲をリクエストすると、範囲エラーを解析できません

私のコードは$範囲の

$range[]= 'sheet1!A:C'; 
$response = $service->spreadsheets_values->get($spreadsheetId, $range); 
$values = $response->getValues(); 

配列や文字列だけであれば一つの値を作品です。 MLTI値を持つ アレイは、RESTに悪いのURLを与える:

$range[]= 'sheet1!A:C'; 
$range[]= 'SHEET2!A:C'; 
$response = $service->spreadsheets_values->get($spreadsheetId, $range); 

次のエラーが返されます。

Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling GET https://sheets.googleapis.com/v4/spreadsheets/[spreadsheetID]/values/Config%21A%3AC,Carte%21A%3AC?key=[my api key]: (400) Unable to parse range: sheet1!A:C,SHEET2!A:C' in C:\Program Files\EasyPHP-12.1\www...\src\Google\Http\REST.php:110 Stack trace: #0 C:\Program Files\EasyPHP-12.1\www...\src\Google\Http\REST.php(62): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request), Object(Google_Client)) #1 [internal function]: Google_Http_REST::doExecute(Object(Google_Client), Object(Google_Http_Request)) #2 C:\Program Files\EasyPHP-12.1\www...\src\Google\Task\Runner.php(174): call_user_func_array(Array, Array) #3 C:\Program Files\EasyPHP-12.1\www....\src\Google\Http\REST.php(46): Google_Task_Runner->run() #4 C:\Program Files\EasyPHP-12.1\www...\src\Google\Client.php(593): Google_Http_REST::execute(Object(Google_Client in C:\Program Files\EasyPHP-12.1\www...\src\Google\Http\REST.php on line 110

おかげ

答えて

0
$service->spreadsheets_values->get($spreadsheetId, $range); 

は、単一の範囲をとります。あなたは2つを送信しようとしているので、エラーが発生しています。あなたがspreadsheet.values.batchget

<?php 
/* 
* BEFORE RUNNING: 
* --------------- 
* 1. If not already done, enable the Google Sheets API 
* and check the quota for your project at 
* https://console.developers.google.com/apis/api/sheets 
* 2. Install the PHP client library with Composer. Check installation 
* instructions at https://github.com/google/google-api-php-client. 
*/ 

// Autoload Composer. 
require_once __DIR__ . '/vendor/autoload.php'; 

$client = getClient(); 

$service = new Google_Service_Sheets($client); 

// The ID of the spreadsheet to retrieve data from. 
$spreadsheetId = ''; // TODO: Update placeholder value. 

$optParams = []; 

// The A1 notation of the values to retrieve. 
$optParams['ranges'] = []; // TODO: Update placeholder value. 

// How values should be represented in the output. 
// The default render option is ValueRenderOption.FORMATTED_VALUE. 
$optParams['valueRenderOption'] = ''; // TODO: Update placeholder value. 

// How dates, times, and durations should be represented in the output. 
// This is ignored if value_render_option is 
// FORMATTED_VALUE. 
// The default dateTime render option is [DateTimeRenderOption.SERIAL_NUMBER]. 
$optParams['dateTimeRenderOption'] = ''; // TODO: Update placeholder value. 

$response = $service->spreadsheets_values->batchGet($spreadsheetId, $optParams); 

// TODO: Change code below to process the `response` object: 
echo '<pre>', var_export($response, true), '</pre>', "\n"; 

function getClient() { 
    // TODO: Change placeholder below to generate authentication credentials. See 
    // https://developers.google.com/sheets/quickstart/php#step_3_set_up_the_sample 
    // 
    // Authorize using one of the following scopes: 
    // 'https://www.googleapis.com/auth/drive' 
    // 'https://www.googleapis.com/auth/drive.readonly' 
    // 'https://www.googleapis.com/auth/spreadsheets' 
    // 'https://www.googleapis.com/auth/spreadsheets.readonly' 
    return null; 
} 
?> 

メモコードを呼び出すべきである

は、ドキュメントから直接リッピングhere

を見つけました
関連する問題