如果将表单设置为收集电子邮件,则通过Google Apps脚本提交Google表单失败 [英] Submitting a Google Form via Google Apps Script fails if Form is set to collect email

查看:145
本文介绍了如果将表单设置为收集电子邮件,则通过Google Apps脚本提交Google表单失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过Apps脚本提交表单时,如果将表单设置为收集用户电子邮件以进行响应,则代码将失败,并显示以下错误:

When submitting a form via Apps script, if the form is set to collect the user e-mail for responses, then the code fails with error:

"很抱歉,无法提交表单回复.请稍等 分钟,然后重试."

"Sorry, the form response could not be submitted. Please wait a few minutes and try again."

我认为Google可能已经做出了一些改变,因为去年有效的代码今年无法正常工作.

I think Google may have changed something as the code that worked last year is not working this year.

错误指向提交"窗口.代码中的一行.或有时,代码会运行,但工作表中或响应"对话框中仍然没有任何内容.形式本身.

The error points at the "submit" line in the code. OR sometimes, the code runs, but still nothing appears in the sheet, or in the "responses" in the form itself.

如果我关闭了收集电子邮件的选项,则它运行良好,并且我在Google工作表中看到了提交的内容,只是没有电子邮件地址.

If I turn off the option to collect e-mail, it runs fine and I see the submission in the Google sheet, just without an e-mail address.

我设置了一个测试表单,将其附加到新的Google工作表中以进行回复,然后粘贴到我的代码中:

I setup a test form, attached it to a new google sheet for responses, and pasted in my code:

function codeVoteDoVoteByForm()
{
  
  // Get the Yes/No Google form
  var myForm = FormApp.openById('File ID Here')

  // Get a list of questions on it
  var questions = myForm.getItems()
 
  // Get question 0 (only one on this form) and mark it as multiple choice
  var qt = questions[0].asMultipleChoiceItem()
  
  // Set the users vote
  var qr = qt.createResponse("I am here")
  
  //Create the response
  var FormResponse = myForm.createResponse()
  var testemail = FormResponse.getRespondentEmail()
  // Submit the response
  FormResponse.withItemResponse( qr );
  var myResponse = FormResponse.submit()
  
  var responseString = myResponse.getTimestamp()
  return "Vote recorded at " + responseString
  
}

我的想法是Google进行了一些更改,因此,现在在运行脚本时,它无法获得用户的电子邮件地址以进行formresponse,但是我找不到任何文档来确认这一点.

My thought is that Google changed something, so now when running a script it's not able to get the users e-mail address for the formresponse, but I can't find any documentation to confirm this.

有什么想法吗?

推荐答案

我认为问题是当您向具有收集电子邮件或经过身份验证的用户限制的表单发送响应时,没有添加电子邮件或对用户进行身份验证.不幸的是,我认为无法通过API发送此类信息,因此在我的情况下:

I think that the problem is when you are sending a reponse to a form that have collect email or authenticated user restrictions, without adding an email or authenticating the user. Unfortunely, I think that is not possible to send this sort of information with the API, so in my case:

  • 我已禁用限制,下一个
  • 我已将回复发送至表单,最后
  • 我再次启用限制

  • I have disabled the restrictions, next
  • I have sent the response to the form, and finally
  • I enable the restrictions again

//disable restrictions temporaly
form.setLimitOneResponsePerUser(false);
form.setRequireLogin(false);
form.setCollectEmail(false);

var questions = form.getItems();

var formResponse = form.createResponse();

for (var i=0; i<questions.length; i++){

  var question = questions[i].asMultipleChoiceItem();
  var response = question.createResponse(correctAnswers[i]);

  formResponse.withItemResponse(response);
}

formResponse.submit();

form.setLimitOneResponsePerUser(true);
form.setRequireLogin(true);
form.setCollectEmail(true); 

这篇关于如果将表单设置为收集电子邮件,则通过Google Apps脚本提交Google表单失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆