Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google Sheets API v4-方法:spreadsheets.values.append_Google Apps Script_Google Sheets_Google Sheets Api_Google Apis Explorer - Fatal编程技术网

Google apps script Google Sheets API v4-方法:spreadsheets.values.append

Google apps script Google Sheets API v4-方法:spreadsheets.values.append,google-apps-script,google-sheets,google-sheets-api,google-apis-explorer,Google Apps Script,Google Sheets,Google Sheets Api,Google Apis Explorer,Google应用程序脚本的Google Sheets API v4方法的正确语法是什么 尝试了以下代码,但出现错误:接收到无效的JSON负载。 function appendRow() { Sheets.Spreadsheets.Values.append("SpreadsheetID", "Sheet1!A:A", "USER_ENTERED", { "values": [[new Date()]] } ); } 谢谢。这个样品怎么样Sheets.Spreadsheets.Values.

Google应用程序脚本的Google Sheets API v4方法的正确语法是什么

尝试了以下代码,但出现错误:
接收到无效的JSON负载。

function appendRow() {
  Sheets.Spreadsheets.Values.append("SpreadsheetID", "Sheet1!A:A", "USER_ENTERED", { "values": [[new Date()]] } );
}

谢谢。

这个样品怎么样<高级Google服务的code>Sheets.Spreadsheets.Values.append()类似于
Sheets.Spreadsheets.Values.append(资源、电子表格ID、范围、可选参数)
。因此,使用您的参数的示例如下所示

样本:
这里最重要的答案对我不起作用。在API的v4中,经过一些尝试和错误之后,下面的工作正常。GoogleSheetsAPI文档到处都是,这无疑将在下一版本中过时!祝所有使用Sheets API的人好运

const request = {
    spreadsheetId: 'SHEET_ID',
    range: 'Sheet1!A:B',
    valueInputOption: 'USER_ENTERED',
    insertDataOption: 'INSERT_ROWS',
    resource: {
        "majorDimension": "ROWS",
        "values": [["Row 1 Col 1","Row 1 Col 2"], ["Row 2 Col 1","Row 2 Col 2"]]
    },
    auth: oAuth2Client,
};

try {
    const response = (await sheets.spreadsheets.values.append(request)).data;
    console.log(JSON.stringify(response, null, 2));
} catch (err) {
    console.error(err);
}

谷歌在JSON Payloads中的范围字段将代码更改为:{“范围”:“Sheet1!A1:D1”,“主要尺寸”:“行”,“值”:[[“门”,“15美元”,“2”,“3/15/2016”],[“引擎”,“100美元”,“1”,“3/20/2016”],];但它给出了错误:
未找到请求的实体。
尽管范围和sheetId的所有信息都正确。看起来它在电子表格的给定范围内找不到实体(“用户输入”)。首先,您确定要使用此方法吗?它是在工作表中找到一些值并在其下添加数据。如果我删除它,它会显示:
提供的参数数量无效。预计仅限3-4人
。而且您提供的代码还表示,[具有“USER_ENTERED”选项]是必需的。真奇怪,为什么谷歌没有提供关于谷歌工作表API v4的完整文档。为什么不将“用户输入”更改为该范围内的某个值?是的,v4文档是一场灾难。@Din欢迎。也谢谢你。
const request = {
    spreadsheetId: 'SHEET_ID',
    range: 'Sheet1!A:B',
    valueInputOption: 'USER_ENTERED',
    insertDataOption: 'INSERT_ROWS',
    resource: {
        "majorDimension": "ROWS",
        "values": [["Row 1 Col 1","Row 1 Col 2"], ["Row 2 Col 1","Row 2 Col 2"]]
    },
    auth: oAuth2Client,
};

try {
    const response = (await sheets.spreadsheets.values.append(request)).data;
    console.log(JSON.stringify(response, null, 2));
} catch (err) {
    console.error(err);
}