gpt4 book ai didi

javascript - https ://docs. 请求失败 google.com 返回代码 400。 chop 的服务器响应:

转载 作者:行者123 更新时间:2023-12-04 10:34:09 25 4
gpt4 key购买 nike

所以我尝试在 https://script.google.com/ 上制作一个脚本将数据从谷歌电子表格自动输入谷歌表单,但我总是收到此代码错误

"Request failed for https://docs.google.com returned code 400. Truncated server response: <!DOCTYPE html><html lang="en" class="m2"><head><link rel="shortcut icon" sizes="16x16" href="https://ssl.gstatic.com/docs/spreadsheets/forms/favic... (use muteHttpExceptions option to examine full response) (line 25, file "Code")"

有人可以帮助我吗?

这里我的代码
function auto_data_entry() {

var formURL="https://docs.google.com/forms/u/0/d/e/1FAIpQLSduXRTFWkeq1ZLRaiGzhmT58oUZSp20FHsT73_qMj8ZpobuqA/formResponse";

var wrkBk = SpreadsheetApp.getActiveSpreadsheet();
var wrkSht= wrkBk.getSheetByName("Sheet1");

var Transaction1 = wrkSht.getRange("A1").getValue();
var Transaction2 = wrkSht.getRange("A2").getValue();
var Transaction3 = wrkSht.getRange("A3").getValue();
var Transaction4 = wrkSht.getRange("A4").getValue();
var Transaction5 = wrkSht.getRange("A5").getValue();

var datamap={"entry.663378019":Transaction1,
"entry.978525821":Transaction2,
"entry.1636658367":Transaction3,
"entry.1490939339":Transaction4,
"entry.2066528728":Transaction5};

var options = {
"method": "post",
"payload": datamap
};

UrlFetchApp.fetch(formURL, options);
}

这里是表 https://docs.google.com/spreadsheets/d/1-sLoKy6npftapr3QxoRIoYozBN6izei0E9uqF4yLg-8/edit?usp=sharing

这是表格 https://docs.google.com/forms/d/e/1FAIpQLSduXRTFWkeq1ZLRaiGzhmT58oUZSp20FHsT73_qMj8ZpobuqA/viewform

谢谢!

最佳答案

您在这里的主要问题是您正在尝试对谷歌表单使用 fetch 方法。 Fetch适用于向网站发出 HTTP 请求,因此尝试对表单执行此操作会过于复杂,因为您需要在该侧创建自定义响应。

自动化数据输入

实现您想要的更简单的方法 是使用 Form Response Apps Script Google Form 文档中的方法 pre filling表格。这段代码将自动从 google 的电子表格中输入数据:

function auto_data_entry(){

var url='YOUR FORM URL';

var wrkBk = SpreadsheetApp.getActiveSpreadsheet();
var wrkSht= wrkBk.getSheetByName("Sheet1")

var Transaction1 = wrkSht.getRange("A1").getValue();
var Transaction2 = wrkSht.getRange("A2").getValue();
var Transaction3 = wrkSht.getRange("A3").getValue();
var Transaction4 = wrkSht.getRange("A4").getValue();
var Transaction5 = wrkSht.getRange("A5").getValue();

var data = [Transaction1,Transaction2,Transaction3,Transaction4,Transaction5];


var form = FormApp.openByUrl(url);
var questions = form.getItems(); //get the different questions you want to pre fill
var FormResponse = form.createResponse();
//set a response from your response data array to the corresponding question until you fill the whole form
for(i=0;i<5;i++){
var qt = questions[i].asTextItem();
var qr = qt.createResponse(data[i]);
FormResponse.withItemResponse( qr );
}
//create a prefilled form
var preurl = FormResponse.toPrefilledUrl();
Logger.log(preurl);

}


NOTE: your pre filled form url is in the log.



自动化表单提交

此外,如果您希望自动化表单 submissions从您的电子表格数据中,您可以使用以下代码:

function auto_submission() {

var url='YOUR FORM URL';

var wrkBk = SpreadsheetApp.getActiveSpreadsheet();
var wrkSht= wrkBk.getSheetByName("Sheet1")

var Transaction1 = wrkSht.getRange("A1").getValue();
var Transaction2 = wrkSht.getRange("A2").getValue();
var Transaction3 = wrkSht.getRange("A3").getValue();
var Transaction4 = wrkSht.getRange("A4").getValue();
var Transaction5 = wrkSht.getRange("A5").getValue();

var data = [Transaction1,Transaction2,Transaction3,Transaction4,Transaction5];


var form = FormApp.openByUrl(url);
var questions = form.getItems(); //get the different questions you want to fill
var FormResponse = form.createResponse();
//set a response from your response data array to the corresponding question until you fill the whole form
for(i=0;i<5;i++){
var qt = questions[i].asTextItem();
var qr = qt.createResponse(data[i]);
FormResponse.withItemResponse( qr );
}
//submit the form
FormResponse.submit();

}


我希望这对您有所帮助,如果您发现任何问题或不理解任何内容,请告诉我。

关于javascript - https ://docs. 请求失败 google.com 返回代码 400。 chop 的服务器响应:,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60267413/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com