Google Classroom Inviter
Google Classroom Inviter
This is a google apps script to easily invite a teacher to all classrooms of another teacher.
To run this script go to script.google.com, create a new script, and paste this over the top of what is already in there
The first time you load this script you need to go to Resources -> Advanced Google Services and enable 'Google Classroom API'
You need to replace the "teacherwithclasses" and the "teachertoadd" with the appropriate teachers email addresses. Will invite the teachertoadd to the first 100 classes that teacherwithclasses teaches.
To view the output go to View -> Logs
function inviteTeacher() { var teacherwithclasses = '[email protected]'; var teachertoadd = '[email protected]'; var alreadyin = []; var optionalArgs = { pageSize: 100, teacherId: teachertoadd }; var response = Classroom.Courses.list(optionalArgs); var courses = response.courses; if (courses && courses.length > 0) { for (i = 0; i < courses.length; i++) { var course = courses[i]; alreadyin.push(course.id); } } var optionalArgs = { pageSize: 100, teacherId: teacherwithclasses }; var response = Classroom.Courses.list(optionalArgs); var courses = response.courses; if (courses && courses.length > 0) { for (i = 0; i < courses.length; i++) { var course = courses[i]; if(alreadyin.indexOf(course.id) == -1){ var toadd = { "courseId": course.id, "role": "TEACHER", "userId": teachertoadd } Classroom.Invitations.create(toadd); Logger.log('%s (%s)', course.name, course.id); } } } else { Logger.log('No courses found.'); } }