542 {错误":{code;:400; messages; quot; quot; quot;是必需的但未指定的“错误”:[{{{;

发布于 2025-02-11 20:42:06 字数 3660 浏览 3 评论 0原文

我在JavaScript中发现了相同错误的解决方案的问题,但无法使其适用于PHP,请帮助

错误: 542 {“ error”:{“ code”:400,“消息” “:”'valueinputoption'是必需的,但未指定”,“错误”:[{“ message”:“”'valueinputoption'是必需的,但未指定的“ valueinputoption”,“ domain”:“ global”:“ global”,“原因”:“ badrequest”}:“ badrequest”} ],“状态”:“ Invalid_argument”}}}}

这是我使用以下代码时遇到的错误:

<?php
$time = time();
$name = $_GET['cname'];
$invoiceNumber = $_GET['invoice'];
$date = $_GET['date'];
$percentage = $_GET['percentage'];
$taxableValue = $_GET['taxableValue'];
$discount = $_GET['discount'];
$invoictotoal = $_GET['total'];
$sgst = $percentage*$taxableValue/100;
echo $discount;
require __DIR__ . '/vendor/autoload.php';

/**
 * Returns an authorized API client.
 * @return Client the authorized client object
 */
function getClient()
{
    $client = new \Google_Client();
    $client->setApplicationName('Google Sheets API PHP Quickstart');
    $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
    $client->setAuthConfig('C:\Users\mitta\Desktop\Seagull\form\credentials.json');
    $client->setAccessType('offline');
    return $client;
}


// Get the API client and construct the service object.
$client = getClient();
$client->addScope(Google\Service\Drive::DRIVE);
$client->setScopes(['https://www.googleapis.com/auth/spreadsheets']);
$service = new Google\Service\Sheets($client);

// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
try{

    $spreadsheetId = '1H6EHEHGsHyRZTE-j8er9DrZjj-b9TkRg0p96K-h90Pc';
    $range = 'Form Responses 1';
    $valuetoinsert = [
        [$time,$name,$invoiceNumber,$date,$percentage,$invoictotoal,$taxableValue,$discount,$sgst,$sgst],
    ];
    $body = new Google_Service_Sheets_ValueRange([
        'values' => $valuetoinsert
    ]);
    $params = [
        'valueInputOption' => 'RAW'
    ];
    $inset = [
        "insertDataOption" => "INSERT_ROWS"
    ];
    $result = $service->spreadsheets_values->append(
        $spreadsheetId,
        $range,
        $body
    );
}
catch(Exception $e) {
    // TODO(developer) - handle error appropriately
    echo $e->getMessage();
}
?>

因此,我添加了Valuinputoption参数,但是我得到了不同的错误

错误: undfult typeError:umpode:umpode( ):参数#2($ array)必须是类型?数组,d:\ xamp \ htdocs \ form \ form \ vendor \ vendor \ google \ apiclient \ apiclient \ src \ src \ google \ service \ services \ resource.php:291 stack跟踪:#0 D:\ Xamp \ htdocs \ form \ vendor \ vendor \ google \ apiclient \ src \ src \ google \ service \ resopy \ resource.php(291):esprode(arnday,'&amp;')#1 d:\ xamp \ xamp \ xamp \ htdoc \ htdoc \ htdoc \ form \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ vendor \ Google \ apiclient \ src \ google \ services \ resource.php(190):google_service_resource-&gt; createrequesturi('v4/varversheets ...',array)#2 d:\ xamp \ xamp \ htdocs \ htdocs \ htdocs \ htdocs \ form \ form \ vendor \ vendor \ vendor \ vendor \ vendor \ apiclient -services\src\Sheets\Resource\SpreadsheetsValues.php(83): Google_Service_Resource->call('append', Array, 'Google\Service\...') #3 D:\xamp\htdocs\form\insert 。 #4 {main}在d:\ xamp \ htdocs \ form \ vendor \ google \ apiclient \ apiclient \ src \ src \ google \ service \ services \ resource.php上,第291行291

使用该错误的代码是SAM,我添加了2个更多参数:

$result = $service->spreadsheets_values->append(
        $spreadsheetId,
        $range,
        $body,
        $inset,
        $params
    );

I found the same problem with the solution for the same error in javascript but couldn't make it work for PHP so please help

ERROR: 542{ "error": { "code": 400, "message": "'valueInputOption' is required but not specified", "errors": [ { "message": "'valueInputOption' is required but not specified", "domain": "global", "reason": "badRequest" } ], "status": "INVALID_ARGUMENT" } }

this is the error i get when i use the following code:

<?php
$time = time();
$name = $_GET['cname'];
$invoiceNumber = $_GET['invoice'];
$date = $_GET['date'];
$percentage = $_GET['percentage'];
$taxableValue = $_GET['taxableValue'];
$discount = $_GET['discount'];
$invoictotoal = $_GET['total'];
$sgst = $percentage*$taxableValue/100;
echo $discount;
require __DIR__ . '/vendor/autoload.php';

/**
 * Returns an authorized API client.
 * @return Client the authorized client object
 */
function getClient()
{
    $client = new \Google_Client();
    $client->setApplicationName('Google Sheets API PHP Quickstart');
    $client->setScopes([\Google_Service_Sheets::SPREADSHEETS]);
    $client->setAuthConfig('C:\Users\mitta\Desktop\Seagull\form\credentials.json');
    $client->setAccessType('offline');
    return $client;
}


// Get the API client and construct the service object.
$client = getClient();
$client->addScope(Google\Service\Drive::DRIVE);
$client->setScopes(['https://www.googleapis.com/auth/spreadsheets']);
$service = new Google\Service\Sheets($client);

// Prints the names and majors of students in a sample spreadsheet:
// https://docs.google.com/spreadsheets/d/1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms/edit
try{

    $spreadsheetId = '1H6EHEHGsHyRZTE-j8er9DrZjj-b9TkRg0p96K-h90Pc';
    $range = 'Form Responses 1';
    $valuetoinsert = [
        [$time,$name,$invoiceNumber,$date,$percentage,$invoictotoal,$taxableValue,$discount,$sgst,$sgst],
    ];
    $body = new Google_Service_Sheets_ValueRange([
        'values' => $valuetoinsert
    ]);
    $params = [
        'valueInputOption' => 'RAW'
    ];
    $inset = [
        "insertDataOption" => "INSERT_ROWS"
    ];
    $result = $service->spreadsheets_values->append(
        $spreadsheetId,
        $range,
        $body
    );
}
catch(Exception $e) {
    // TODO(developer) - handle error appropriately
    echo $e->getMessage();
}
?>

so i added the valuInputOption parameter but then i get different error

error: Uncaught TypeError: implode(): Argument #2 ($array) must be of type ?array, string given in D:\xamp\htdocs\form\vendor\google\apiclient\src\Google\Service\Resource.php:291 Stack trace: #0 D:\xamp\htdocs\form\vendor\google\apiclient\src\Google\Service\Resource.php(291): implode(Array, '&') #1 D:\xamp\htdocs\form\vendor\google\apiclient\src\Google\Service\Resource.php(190): Google_Service_Resource->createRequestUri('v4/spreadsheets...', Array) #2 D:\xamp\htdocs\form\vendor\google\apiclient-services\src\Sheets\Resource\SpreadsheetsValues.php(83): Google_Service_Resource->call('append', Array, 'Google\Service\...') #3 D:\xamp\htdocs\form\insert.php(54): Google\Service\Sheets\Resource\SpreadsheetsValues->append('1H6EHEHGsHyRZTE...', 'Form Responses ...', Object(Google\Service\Sheets\ValueRange), Array, Array) #4 {main} thrown in D:\xamp\htdocs\form\vendor\google\apiclient\src\Google\Service\Resource.php on line 291

The code used for this error is the sam and i added 2 more parameters:

$result = $service->spreadsheets_values->append(
        $spreadsheetId,
        $range,
        $body,
        $inset,
        $params
    );

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文