且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用应用程序脚本创建课堂

更新时间:2023-10-21 13:35:16

根据文档,您必须指定 DriveFile 对象 JSON。


$ b $ pre $ driveFile:{
id:theDocIdString,
title:theDocTitleString ,
alternateLink:urlToFileString,
thumbnailUrl:imgThumbnailString
}

你当然可以全力以赴或者使用变量循环访问资源。


I'm trying to create Google clas-s-rooms 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 = Clas-s-room.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 Clas-s-room but with no mention of the course material set.

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.