Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.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
Flutter 可以在http.post()方法上删除google工作表行吗?_Flutter_Google Apps Script_Google Sheets Api - Fatal编程技术网

Flutter 可以在http.post()方法上删除google工作表行吗?

Flutter 可以在http.post()方法上删除google工作表行吗?,flutter,google-apps-script,google-sheets-api,Flutter,Google Apps Script,Google Sheets Api,我从Flatter应用程序打了一个http.put()电话,把我的数据放在谷歌表单上。我无法真正实现.delete()方法来删除行,所以现在仍然尝试使用put方法来删除行。当按下“删除”按钮时,我将变量的所有值更改为“已删除”,并将“数量”的值更改为我要删除的项目,并使用get()将所有这些内容传递给google脚本。(我知道…非常硬编码:),无论如何都要努力完成它:D)所以在我的谷歌脚本中,我把条件: 是否必须使用http.delete()方法,或者我的代码中是否有错误?附言:只是个初学者

我从Flatter应用程序打了一个http
.put()
电话,把我的数据放在谷歌表单上。我无法真正实现
.delete()
方法来删除行,所以现在仍然尝试使用
put
方法来删除行。当按下“删除”按钮时,我将变量的所有值更改为“已删除”,并将“数量”的值更改为我要删除的项目,并使用
get()
将所有这些内容传递给google脚本。(我知道…非常硬编码:),无论如何都要努力完成它:D)所以在我的谷歌脚本中,我把条件:


是否必须使用
http.delete()
方法,或者我的代码中是否有错误?附言:只是个初学者

应用程序脚本将您限制为
get
post
——这就是为什么只有
doGet()
doPost()才能接收HTTP请求的原因。您不能使用任何其他HTTP方法,如delete、put或patch

您的代码中还有几个错误:

  • 如果没有
    catch
    ,就不能进行
    try
    。应用程序脚本甚至不应该允许您保存这些内容
  • 该方法需要的是行号,而不是数量。如果要删除多行,请使用该方法
function doPost(request){
  
  var sheet = SpreadsheetApp.openById("1AVouGZs3U2I4xM941sKWqgfJzyiUgP8-1lTI4gTX4tg");
        
    var name = request.parameter.name;
    var product = request.parameter.product;
    var quantity = request.parameter.quantity;
  
 if (name != "delete") { 
 try{
   
  sheet.appendRow([name, product, quantity]);

  }

}
 
   if (name == "delete" ) { 
   try{
   sheet.deleteRow(quantity); // quantity indicates index of item that needs to be deleted

  }