Kang CiFong
Kang CiFong

Reputation: 77

INPUT_VALUE_OPTION_UNSPECIFIED issue on Google Spread Sheet Api on PHP Client

According to the question asked by "Setting PUT request body with PHP" 1, I use the method mentioned in the answer to use curl to post the content to my spreadsheet by php.

And I got the following error message in return, so as the result from the Postman query. The content of this spreadsheet should be kept private.

{ "error": { "code": 401, "message": "Request had invalid authentication credentials.", "status": "UNAUTHENTICATED" } }

So I want to use the method mentioned in the quickstart guide 2 to organize the Postbody in PHP.

Below is my code

$range = "general!A9:E";
$vRan = new Google_Service_Sheets_ValueRange();
$vRan->setMajorDimension("ROWS");
$vRan->setRange($range);
$val = array
  (
    array(time(), "General", "PHPName", "PHPCompany","[email protected]")
 );
$vRan->setValues($val);

$type="USER_ENTERED";
$response = $service->spreadsheets_values->update($spreadsheetId, $range, $vRan,array($type));

And I got those error messages

Illegal string offset 'type' in /Users/user1/Sites/gas/google-api-php-client/src/Google/Http/REST.php on line 151 PHP Warning: Illegal string offset 'location' in /Users/user1/Sites/gas/google-api-php-client/src/Google/Http/REST.php on line 154 PHP Warning: Illegal string offset 'location' in /Users/user1/Sites/gas/google-api-php-client/src/Google/Http/REST.php on line 156 PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message 'Error calling PUT https://sheets.googleapis.com/v4/spreadsheets/[ID]/values/general%21A9%3AH: (400) Invalid valueInputOption: INPUT_VALUE_OPTION_UNSPECIFIED' in /Users/user1/Sites/gas/google-api-php-client/src/Google/Http/REST.php:110

How could I manage to correctly organize the Iuput value option?

Upvotes: 1

Views: 1205

Answers (1)

Kang CiFong
Kang CiFong

Reputation: 77

I solve this issue and successfully put the data onto google spread sheet by modifying the data structure of the last parameter from array("RAW") to array("valueInputOption"=>"RAW")

$response = $service->spreadsheets_values->update($spreadsheetId, $range, $vRan, array("valueInputOption"=>$type));

Upvotes: 1

Related Questions