首页 > 解决方案 > 有没有办法使用 Google People API 将用户名提取到 Google 表单中?

问题描述

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

我查看了此处的 Google People API 文档https://developers.google.com/apps-script/advanced/people并尝试添加他们拥有的示例代码并将结果推送为对文本问题的响应。我启用了 API,并按照说明将范围添加到 json 文件中,但没有填充任何内容。

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

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

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 自动填充表单中的名称,如果是这样,如何使它真正起作用?

谢谢,赛斯

标签: google-apps-scriptgoogle-apigoogle-formsgoogle-people-api

解决方案


推荐阅读