Есть ли способ вывести имя пользователя с помощью Google People API в форму Google? - PullRequest
0 голосов
/ 23 апреля 2019

Я пытаюсь программно создать форму Google, которая будет автоматически вводить имя ученика.

Я посмотрел документацию по API Google People здесь https://developers.google.com/apps-script/advanced/people и попытался добавить пример кода, который у них есть, и выдвинуть результат в ответ на текстовый вопрос. У меня включен 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, и если да, то как это сделать на самом деле?

Спасибо, Сет

...