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 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误