Creating Classroom using App Script

自闭症网瘾萝莉.ら 提交于 2019-12-25 05:17:14

问题


I'm trying to create Google classrooms from a spreadsheet using App Script. I can create the classes successfully, but it's not adding the course materials (1 Doc) to the about page.

This is the code I am using and I've tried using the API reference to no avail.

Can someone please advise me on how to correctly format the courseMaterialSets to include a Google Doc from my drive.

var create = Classroom.Courses.create({
"ownerId": '-My email address-',
  "name": getData[i][0],
  "section": getData[i][1],
  "descriptionHeading": getData[i][2],
  "description": getData[i][2],
    "courseMaterialSets" : [{
            "title" : 'Course Outline',
            "materials" : [{
                    "driveFile" : { 
                            "id" : getData[i][5],
                            "title" : 'Course Outline' ,
                            "alternateLink": getData[i][4], 
                            "thumbnailUrl" : 'https://drive.google.com/uc?export=download&id=-Image ID-',

                    },
                }
            ]
        }
    ]
})
}
Logger.log(create)
}

Thank you.

EDIT

I've updated the code to reflect the suggestions in the comments and logged the value of var create which returns all of the info of the newly created Classroom but with no mention of the course material set.


回答1:


According to the documentation you have to specify the DriveFile object with JSON.

"driveFile" : {
   "id":            theDocIdString,
   "title":         theDocTitleString,
   "alternateLink": urlToFileString,
   "thumbnailUrl":  imgThumbnailString 
   }

You can of course pull all of this data from a sheet or use variables to loop through resources.




回答2:


Here is the code I tried to successfully create a course, but I also do not get the course materials to attach to the ABOUT tab of the Google Classroom created.

function createCourse() {
  var resource = {
    name: "XYZ course",
    room: "The Great Hall",
    ownerId: "me",
    courseMaterialSets: [{
      title: "course materials",
      materials: [
      {

        driveFile: {
          id: "insert id of google drive file" 

        }


      }
      ],
  }],
  }
  var newCourse = Classroom.Courses.create(resource);


}

I also tried creating the course and then accepting the course in Google Classroom and the trying to add the classroom set. This also was not successful.

function addClassSet() {
  var id = "course id obtained with sample script in documentation";
  var resource = {
    name: "XYZ course",
    room: "The Great Hall",
    courseMaterialSets: [{
      title: "course materials",
      materials: [
      {

        driveFile: {
          id: "drive file id" //drive file was not added

        }


      }
      ],
  }],
    description: "This is a trial course", //this worked
  }
  Classroom.Courses.update(resource, id);
}

Is it because the documentation states that the courseMaterialsSets is Read only???



来源:https://stackoverflow.com/questions/43888104/creating-classroom-using-app-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!