集成php和google sheets api时出错

集成php和google sheets api时出错,php,google-sheets-api,Php,Google Sheets Api,我试图将GoogleSheetsAPI与php集成,以便捕获html表单数据并将其附加到电子表格中,但我面临一个奇怪的错误 下面是php代码段: $client = new \Google_Client(); $client->setApplicationName('WEBMONK_QUOTATION_REQUESTS'); $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]); $client->setAcces

我试图将GoogleSheetsAPI与php集成,以便捕获html表单数据并将其附加到电子表格中,但我面临一个奇怪的错误

下面是php代码段:

$client = new \Google_Client();
$client->setApplicationName('WEBMONK_QUOTATION_REQUESTS');
$client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
$client->setAccessType('offline');
$client->setAuthConfig('../credentials.json');
$service = new Google_Service_Sheets($client);
$spreadsheets_id = '1S2LPDl5XmOEx4TQ3cR4yZ4SAALcxXRyxU5nFMU7RW0I';
$range = 'QUOTESHEET';

$sheet_rows = [
    strval($datetime),
    strval($name),
    strval($email),
    strval($url),
    strval($extras)
];

$body = new Google_Service_Sheets_ValueRange(['values' => [$sheet_rows]]);
$params = ['valueInputOption' => 'RAW'];
$insert = ['insertDataOption' => 'INSERT_ROWS'];
$result = $service->spreadsheets_values->append(
    $spreadsheets_id,
    $range,
    $body,
    $params,
    $insert
);
以下是我得到的错误:

<br />
<b>Fatal error</b>:  Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php:291
Stack trace:
#0 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(291): implode(Array, '&amp;')
#1 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php(190): Google_Service_Resource-&gt;createRequestUri('v4/spreadsheets...', Array)
#2 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient-services\src\Google\Service\Sheets\Resource\SpreadsheetsValues.php(64): Google_Service_Resource-&gt;call('append', Array, 'Google_Service_...')
#3 C:\xampp\htdocs\webric.org\api\post\insert.php(68): Google_Service_Sheets_Resource_SpreadsheetsValues-&gt;append('1S2LPDl5XmOEx4T...', 'QUOTESHEET', Object(Google_Service_Sheets_ValueRange), Array, Array)
#4 {main}
  thrown in <b>C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\Google\Service\Resource.php</b> on line <b>291</b><br />

致命错误:未捕获类型错误:内爆():参数#2($array)必须是数组类型,字符串以C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\google\Service\Resource.php:291给出 堆栈跟踪: #0 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\google\Service\Resource.php(291):内爆(数组“&;”) #1 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\google\Service\Resource.php(190):google\u Service\u Resource-createRequestUri('v4/spreadsheets…',数组) #2 C:\xampp\htdocs\webric.org\api\vendor\google\apiclient services\src\google\Service\Sheets\Resource\SpreadsheetsValues.php(64):google\u Service\u Resource-call('append',Array,'google\u Service\uu…')) #3 C:\xampp\htdocs\webric.org\api\post\insert.php(68):Google_服务_Sheets\u资源_电子表格VALUES-append('1S2LPDl5XmOEx4T…','QUOTESHEET',对象(Google_服务_Sheets\u ValueRange),数组,数组) #4{main} 在第291行的C:\xampp\htdocs\webric.org\api\vendor\google\apiclient\src\google\Service\Resource.php中抛出
到目前为止,据我所知,Google库中的内爆()函数由于参数类型错误而出现故障。但是我没有发现我上面的php代码有任何错误。我已经完成了这里提到的google sheets和php集成过程:

PHP版本:8.0.0, 谷歌API客户端:2.0

请告诉我哪里出了问题。提前感谢。

您的价值观一定有问题 通过将
$body
修改为

$body=新Google\u服务\u表单\u值范围([
“值”=>[[1,2,3]]
]);
如果此请求对您有效-记录
[$sheet\u rows]
以比较结构并查看错误

PS:除了快速启动之外,您的值也肯定有问题 通过将
$body
修改为

$body=新Google\u服务\u表单\u值范围([
“值”=>[[1,2,3]]
]);
如果此请求对您有效-记录
[$sheet\u rows]
以比较结构并查看错误


PS:除了快速启动之外,在切换到PHP8.0(以前使用PHP7.2可以正常工作)之后,也有同样的问题

与以前的版本相比,PHP8.0中的introde()函数基本上切换了两个参数。我查看了Google库中Resource.php文件的最新版本,您应该看到第303行已经反映了这些更改

我转到Resource.php文件并替换了

$requestUrl .= '?' . implode($queryVars, '&');


它又开始工作了。希望有帮助

在切换到PHP8.0(以前PHP7.2可以正常工作)后,也出现了同样的问题

与以前的版本相比,PHP8.0中的introde()函数基本上切换了两个参数。我查看了Google库中Resource.php文件的最新版本,您应该看到第303行已经反映了这些更改

我转到Resource.php文件并替换了

$requestUrl .= '?' . implode($queryVars, '&');


它又开始工作了。希望有帮助

这是谷歌api库中的一段代码。我还没有看过这些代码。您传递给其中一个调用的参数应该是数组,但不是数组。检查手册中所有您正在进行的调用,它是google api库中的代码。我还没有看过这些代码。您传递给其中一个调用的参数应该是数组,但不是数组。检查手册中您正在拨打的所有电话