简体   繁体   English

卡在 Quickstart 检查学生参加 Google Meet 课程的情况

[英]Stuck with Quickstart Check student attendance in Google Meet courses

Thank you in advance of any input;提前感谢您的任何意见; I'm using the G Suite Developer Quickstart for a Meet attendance script https://developers.google.com/gsuite/add-ons/editors/sheets/quickstart/attendance我正在使用 G Suite Developer Quickstart 作为 Meet 出席脚本https://developers.google.com/gsuite/add-ons/editors/sheets/quickstart/attendance

However while getting the roaster of the class i am able to pull only 31 names don't know what i am missing here, been some time(7 years) with the coding.然而,在获得 class 的烘焙机时,我只能提取 31 个名称,不知道我在这里遗漏了什么,编码已经有一段时间(7 年)了。

function onOpen() {
  var ui = SpreadsheetApp.getUi();
  ui.createMenu('Options')
      .addItem("Import Last 5 Courses", 'importCourses')
      .addItem('Check Attendance on Current Sheet', 'checkAll')
      .addToUi();
}

/*
  Description: Option for teachers to import their
  most 5 recently created courses
*/
function importCourses() {
  var optionalArgs = {
    teacherId: 'me',
    pageSize: 5
  };
  var response = Classroom.Courses.list(optionalArgs);
  var courses = response.courses
  for (var i = 0; i < 5; i++) {
    var courseName = courses[i].name
    var courseId = courses[i].id
    insertCourse(courseName, courseId)
  }
}

/*
  Description: Create the Sheet for Course
  @param {String} courseName - Name of Course
  @param {String} courseId - Corresponding Classroom ID
*/
function insertCourse(courseName, courseId) {
    var spreadsheetName = courseName + "(" + courseId + ")"
    var activeSpreadsheet = SpreadsheetApp.getActiveSpreadsheet();
    var yourNewSheet = activeSpreadsheet.getSheetByName(spreadsheetName);

    if (yourNewSheet != null) {
        return
    }
    yourNewSheet = activeSpreadsheet.insertSheet();
    yourNewSheet.setName(spreadsheetName);
    yourNewSheet.appendRow(['Student Name', 'Email Address', 'Replace with Meet Code'])
    yourNewSheet.setFrozenRows(1)
    var studentNames = getRoster(courseId)["studentNames"]
    var studentEmails = getRoster(courseId)["studentEmails"]
    for (var i = 0; i < studentNames.length; i++) {
      yourNewSheet.appendRow([studentNames[i],studentEmails[i]])
    }
    yourNewSheet.autoResizeColumns(1, 2)
    yourNewSheet.setFrozenColumns(2)
  }

/*
  Description: Adds the course's students to the course sheet
  @param {String} courseId - Corresponding Classroom ID
*/
function getRoster(courseId) {
  var studentNames = []
  var studentEmails = []
  var optionalArgs = {
      pageSize: 100
  };
  var response = Classroom.Courses.Students.list(courseId, optionalArgs)
  var students = response.students

  for (var i = 0; i < 100; i++) {
    try {
      studentNames.push(students[i].profile.name.fullName)
      studentEmails.push(students[i].profile.emailAddress)
    } catch (err) {
       return { "studentNames":studentNames, "studentEmails":studentEmails }
   }
 }
}

/*
  Description: Retrieves the Meet code from the Course Sheet
  and uses helper function to check attendance
*/
function checkAll() {
  var ss = SpreadsheetApp.getActiveSheet();
  var sheet = ss.getDataRange().getValues();
  for (var i = 2; i < sheet.length * 100; i++){
    var meetCode = getCleanCode(sheet[0][i])
    // No Meet code given
    if (meetCode == null) {
      break;
    }
    else {
      // check whether each student was present in Meet
      checkMeet(meetCode, i+1);
    }
  }
}

/*
  Description: Checks the Meet for attendance of the given student
  @param {String} meetCode - Raw Meet Code from Course Sheet
  @param {Integer} index - Index corresponding to the Student's row
  in the Course Sheet
*/
function checkMeet(meetCode, index) {
  // universal settings - static
  var userKey = 'all';
  var applicationName = 'meet';
  var ss = SpreadsheetApp.getActiveSheet();
  var sheet = ss.getDataRange().getValues();
  for (var i = 0; i < sheet.length-1; i++) {
    var emailAddress = sheet[i+1][1]
    var optionalArgs = {
      event_name: "call_ended",
      filters: "identifier==" + emailAddress + ",meeting_code==" + meetCode
    };
    try {
      var response = AdminReports.Activities.list(userKey, applicationName, optionalArgs);
      var activities = response.items;
      if (activities == null) {
        markAbsent(ss,i+2,index)
      }
      else {
        markPresent(ss,i+2,index)
      }
    } catch (err) {
        continue
     }
  }
}

/*
  Description: Strips any "-' Characters to match needed format
  for Reports API
  @param {String} meetCode - Raw Meet Code from Course Sheet
*/
function getCleanCode(meetCode) {
  try{
    return code.replace("/-/g","")
  } catch (err) { return code; }
}

/*
  Description: Marks the student as absent for their corresponding cell
  @param {Object} sheet - Course Sheet object
  @param {Integer} i - Index of Sheet cell column to be filled
  @param {Integer} j - Index of Sheet cell row to be filled
*/
function markAbsent(sheet, i, j) {
    var cell = sheet.getRange(i, j);
    cell.setValue("Absent");
}

/*
  Description: Marks the student as absent for their corresponding cell
  @param {Object} sheet - Course Sheet object
  @param {Integer} i - Index of Sheet cell column to be filled
  @param {Integer} j - Index of Sheet cell row to be filled
*/
function markPresent(sheet, i, j) {
    var cell = sheet.getRange(i, j);
    cell.setValue("Present");
}

@Cooper Let me start by apologizing for not properly pasting the code and responding late:-- @Cooper 首先让我为没有正确粘贴代码和迟到回复而道歉:--

The issue was with getRoster() code, and as rightly pointed by @Cooper, the issue got resolved by using nextPageToken.问题出在 getRoster() 代码上,正如@Cooper 正确指出的那样,该问题已通过使用 nextPageToken 得到解决。 Here is how i modified the function这是我修改 function 的方法

function getRoster(courseId) {
  var studentNames= []
  var studentEmails= []
  var students
  var response
  var optionalArgs = {
      pageSize: 200,
      pageToken: ""
       };

  for(var i=0; i < 4; i++){
        response = Classroom.Courses.Students.list(courseId, optionalArgs)
        students = response.students 
       for (var j = 0; j < students.length; j++) {

            studentNames.push(students[j].profile.name.fullName)
            studentEmails.push(students[j].profile.emailAddress)
            }

      if(response.nextPageToken == null){

             return { "studentNames":studentNames, "studentEmails":studentEmails }
             }

      optionalArgs = {
      pageSize: 200,
      pageToken: response.nextPageToken
       };

      Logger.log('I LOOP 1',i);  
    }


  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 卡在 G Suite 开发人员快速入门中以“检查学生在 Google Meet 课程中的出勤率” - Stuck at G Suite Developer Quickstart for “check student attendance in Google Meet courses” 如何在定期的 google meet 中查看学生的出勤情况? - How can I check student attendance in recurring google meet's? G Suite 开发人员表快速入门教程:“检查学生出勤”中的 TypeError - G Suite Developer Sheets Quickstart tutorial: TypeError in “check student attendance” 如何生成 Google Meet Participants 的出席报告 - How to generate the attendance report of Google Meet Participants 查找 Google Meet 特定开始时间以参加会议 - Find Google Meet specific startTime to take attendance 如何使用 Google App Scripts 在学生考勤表的最后一行添加彩色条纹? - How to add a color stripe to every last row of a student attendance sheet using Google App Scripts? Javascript Google API快速入门错误 - Javascript google API quickstart error Google 应用程序脚本快速入门教程无法正常工作 - Google apps script quickstart tutorial not working as it should Google Sheets API快速入门(v4)问题 - Issue with google sheets API quickstart (v4) 使用 Google Apps Script 和 Google Classroom 创建学生 - Creating a student with Google Apps Script & Google Classroom
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM