douju8113 2019-07-23 20:39
浏览 340

致命错误:未捕获Google_Service_Exception:{“error”:{“code”:400,“message”:“收到的JSON有效负载无效。 未知名称\“名称\”

I often try to append data to my google sheet. Most of the time I get an error. I searched at Google and I got a few possible ways of solving this error. Most of the proposed solutions are not working for me due to outdated code. Unfortunately, I've been unable to solve the error.

Here is my code:

<?php
require __DIR__ . '/vendor/autoload.php';


define('SCOPES', implode(' ', array(
    Google_Service_Sheets::SPREADSHEETS,
    Google_Service_Sheets::DRIVE,
    Google_Service_Sheets::DRIVE_FILE) 
));
/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */

function getClient() {
    $client = new Google_Client();
    $client->setAuthConfig('credentials.json');
    $client->setApplicationName('theName');
    $client->setScopes(SCOPES);
    return $client;
}

// Get the API client and construct the service object.
$client = getClient();
$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
$spreadsheetId = '1wAxarp4q9yo7kUUMaA3RudgmSTab53Dc9fReSbyreeM';
$range = 'Sheet1!A1:Z';

// $post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); 

$firstName = "Mamunur";
$roll = "5200";
$class = "class";

$values = [
    'Name'         => $firstName,
    'Roll'          => $roll,
    'Class'      => $class,
    'Dev'           =>"dev"
];
$requestBody = new Google_Service_Sheets_ValueRange([
    'values' => [$values]
]);

$params = [
    'valueInputOption' => 'ROW'
];


$result = $service->spreadsheets_values->append($spreadsheetId, $range, $requestBody, $params);
printf("%d cells appended.", $result->getUpdates()->getUpdatedCells());
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 聚类分析或者python进行数据分析
    • ¥15 如何用visual studio code实现html页面
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?