是否可以使用Google People API将用户的名称提取到Google表单中?

时间:2019-04-23 15:39:37

标签: google-apps-script google-api google-form google-people

我正在尝试以编程方式创建一个Google表单,该表单将自动输入学生姓名。

我在https://developers.google.com/apps-script/advanced/people处查看了Google People API文档,并尝试添加他们拥有的示例代码,并将结果作为对文本问题的答复。我已启用API,并按照指示将范围添加到json文件,但未填充任何内容。

我知道有一个复选框可以自动获取他们的电子邮件地址,但是出于某些原因,我们使用学生证号作为电子邮件地址,而不是使用学生姓名作为电子邮件地址,因此该数据对我们来说不是很有用目的在这里。

这是我的代码,其中包含一些信息。

function myFunction() {
var form = FormApp.create('NHS Student Information Survey');
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var range = sheet.getDataRange();
var values = range.getValues();
var listofteachernames = [];

var people = People.People.getBatchGet({
    resourceNames: ['people/me'],
    personFields: 'names'
  });


form.setDescription(
"High School \n"+
"Address \n"+
"Mr. teacher, NHS Advisor \n"+
" \n"+
"Submissions are due before date \n"+
" \n"+
"DIRECTIONS: Please complete all sections. Every bit of information can be used by the Faculty Council to assist with the selection process. Completion of this form does not guarantee selection. \n"+
" \n"+
"You are advised to prepare your responses in advance before you begin filling out this online form as you can not save information and return later to finish. Also, after you hit submit and before you log off, be sure to wait for the confirmation page indicating that your submission was received."

);

  form.addTextItem().setTitle("Name").createResponse(people);

  form.addMultipleChoiceItem()
     .setTitle("Current Grade")
     .setChoiceValues(["10th", "11th"]);

  form.addParagraphTextItem().setTitle("Activities").setHelpText("List any extra-curricular or co-curricular activities in which you have participated during high school. Include clubs, teams, music groups, church groups, scouting, etc. Please put a return (press enter) after each activity so that it shows as a vertical list.");

  form.addParagraphTextItem().setTitle("Awards").setHelpText("These should be awards or recognition associated with the above activities or with other organizations. Please put a return (press enter) after each award so that it shows as a vertical list.");

  form.addParagraphTextItem().setTitle("Service").setHelpText("List any activity that might be considered volunteer service to others (family or community) and for which you received no payment; this might include such things as doing regular housework for an elderly relative, working at a soup kitchen, helping to raise funds for charity, helping to clean a park with a church group, coaching a younger group of students in a sport or cheer leading, etc. After each activity, include in parenthesis the approximate number of hours you spent doing that activity. If it is a reoccurring event, then indicate how many times per week or month you do this service activity. Please put a return (press enter) after each service activity so that it shows as a vertical list.");

  form.addParagraphTextItem().setTitle("Work Experience").setHelpText("List any work experiences (those for which you were paid) that you have had since the 9th grade. Please put a return (press enter) after each work experience so that it shows as a vertical list.");

  form.addParagraphTextItem().setTitle("Leadership Positions").setHelpText("List all elected or appointed leadership positions held in school, community, or work activities. List only those positions in which you were directly responsible for directing or motivating others; for example: student council, club officer, team captain, chairperson, community leader etc. Again, please put a return (press enter) after each leadership position so that it shows as a vertical list.");

  form.addParagraphTextItem().setTitle("Individual Statement").setHelpText("In one paragraph, tell us why you would like to be considered for NHS membership.");

  form.addCheckboxItem().setTitle("Agreement").setHelpText("I ATTEST THAT THE INFORMATION I AM PROVIDING THE FACULTY COUNCIL FOR NHS MEMBERSHIP CONSIDERATION IS ACCURATE TO THE BEST OF MY KNOWLEDGE.").setChoiceValues(["I agree to the above statement"]);


  for (row=2; row<=values.length; row++){
    var orignallist = sheet.getRange(row,1).getValue();
    listofteachernames.push(orignallist);
  }
 var teacherchoice = form.addCheckboxItem().setTitle("Teacher Evaluators").setHelpText("Please choose eight teachers who can provide an evaluation of your character and leadership qualities. At least five must be teachers who you had during 1st or 2nd trimester of this school year. One of the eight may be your homeroom adviser and no more than two may be teachers you had last year. You may NOT list a coach, director or extracurricular adviser unless they were also your teacher and meet the above guidelines. The evaluation form will be sent directly to, and received directly from, the teachers you choose. You don't need to do anything else after you select the teachers below.")
  .setChoiceValues(listofteachernames);

  var checkBoxValidation = FormApp.createCheckboxValidation()
  .requireSelectExactly(8)
  .build();
teacherchoice.setValidation(checkBoxValidation);

}

是否有人了解这是否能以我正在考虑使用People API在表单中自动填充名称的方式起作用,以及如何使其真正起作用?

谢谢, 赛斯

0 个答案:

没有答案