input_value_option_未指定的问题谷歌电子表格Api在PHP客户端


INPUT_VALUE_OPTION_UNSPECIFIED issue on Google Spread Sheet Api on PHP Client

根据"用PHP设置PUT请求体" 1的问题,我使用答案中提到的方法,使用curl通过PHP将内容发布到我的电子表格中。

,我得到了以下错误消息作为返回,所以从Postman查询的结果。这个电子表格的内容应该保密。

{"错误":{"代码":401年,"message": "请求具有无效的身份验证凭证。","状态":"未经证实的"}}

所以我想使用快速入门指南2中提到的方法来组织PHP中的Postbody。

下面是我的代码
$range = "general!A9:E";
$vRan = new Google_Service_Sheets_ValueRange();
$vRan->setMajorDimension("ROWS");
$vRan->setRange($range);
$val = array
  (
    array(time(), "General", "PHPName", "PHPCompany","mail@php.com")
 );
$vRan->setValues($val);
$type="USER_ENTERED";
$response = $service->spreadsheets_values->update($spreadsheetId, $range, $vRan,array($type));

我得到了那些错误信息

非法字符串偏移'类型'在/Users/user1/Sites/gas/Google -api-php-client/src/Google/Http/REST.php第151行PHP警告:第154行/Users/user1/Sites/gas/Google -api- PHP -client/src/Google/Http/REST.php中的非法字符串偏移'location'PHP警告:第156行/Users/user1/Sites/gas/Google -api- PHP -client/src/Google/Http/REST.php中的非法字符串偏移'location'PHP致命错误:未捕获的异常'Google_Service_Exception',消息' error calling PUT https://sheets.googleapis.com/v4/spreadsheets/[ID]/values/general%21A9%3AH: (400) Invalid valueInputOption: INPUT_VALUE_OPTION_UNSPECIFIED'在/Users/user1/Sites/gas/Google -api- PHP -client/src/Google/Http/REST.php:110

我怎样才能正确地组织输出值选项?

我解决了这个问题,并通过修改最后一个参数的数据结构从array("RAW")到array("valueInputOption"=>"RAW")成功地将数据放到google电子表格上

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