admin管理员组文章数量:1395225
Attempting to retrieve course materials using the code below reports "no Materials found" but the Classroom has multiple entries as Posted and Draft. All scopes are in place and a similar call for courseWork is successful.
function getMaterials() {
ScriptApp.requireAllScopes(ScriptApp.AuthMode.FULL);
var sourceCourseId = "696613911962"; // Replace with your course ID // 759489185424 TUC Bullying & 962 is Study Skills
// Get materials (all)
try {
var destinationMaterialsResponse = Classroom.Courses.Materials.list(sourceCourseId);
Logger.log("Raw Materials Response: " + JSON.stringify(destinationMaterialsResponse)); // Log the entire response
if (destinationMaterialsResponse) {
if (destinationMaterialsResponse.materials) {
Logger.log("Materials: " + JSON.stringify(destinationMaterialsResponse.materials));
} else {
Logger.log("Materials property is missing or empty.");
}
} else {
Logger.log("Destination Materials Response is null or undefined.");
}
} catch (e) {
Logger.log("Error getting materials: " + e);
}
}
Have I made an error? For CourseWork I have found that the state has to be declared, though I believe that Materials should be returned regardless of state (PUBLISHED or DRAFT)
Attempting to retrieve course materials using the code below reports "no Materials found" but the Classroom has multiple entries as Posted and Draft. All scopes are in place and a similar call for courseWork is successful.
function getMaterials() {
ScriptApp.requireAllScopes(ScriptApp.AuthMode.FULL);
var sourceCourseId = "696613911962"; // Replace with your course ID // 759489185424 TUC Bullying & 962 is Study Skills
// Get materials (all)
try {
var destinationMaterialsResponse = Classroom.Courses.Materials.list(sourceCourseId);
Logger.log("Raw Materials Response: " + JSON.stringify(destinationMaterialsResponse)); // Log the entire response
if (destinationMaterialsResponse) {
if (destinationMaterialsResponse.materials) {
Logger.log("Materials: " + JSON.stringify(destinationMaterialsResponse.materials));
} else {
Logger.log("Materials property is missing or empty.");
}
} else {
Logger.log("Destination Materials Response is null or undefined.");
}
} catch (e) {
Logger.log("Error getting materials: " + e);
}
}
Have I made an error? For CourseWork I have found that the state has to be declared, though I believe that Materials should be returned regardless of state (PUBLISHED or DRAFT)
Share Improve this question asked Mar 27 at 13:03 Class AdminClass Admin 134 bronze badges3 Answers
Reset to default 2The autocomplete doesn't include Materials.
The Classroom API docs have Material type, but not a REST resource with such name. Try using CourseWorkMaterials instead.
Agreeing to Wicket:
There are no REST resource named Materials
in Google Classroom API but instead using CourseWorkMaterials
to retrieve course work materials.
To make this work change the Materials
to CourseWorkMaterials
and in order to have a response that returns all states such as PUBLISHED, DRAFT and DELETED
we need to add a second parameter called optionalArgs
and add the CourseWorkState object
.
Optional arguments.
Returns a list of course work material that the requester is permitted to view. Course students may only view PUBLISHED course work material. Course teachers and domain administrators may view all course work material.
const getAllMaterials = Classroom.Courses.CourseWorkMaterials.list(courseId, {
courseWorkMaterialStates: ["PUBLISHED", "DRAFT", "DELETED"]
})
Reference:
CourseWorkState
Correcting the call to CourseWorkMaterials.list and using the optional arguments solved my issue
const getAllMaterials = Classroom.Courses.CourseWorkMaterials.list(courseId, {
courseWorkMaterialStates: ["PUBLISHED", "DRAFT", "DELETED"]
})
本文标签: google classroomApp script API fails to return Course MaterialsStack Overflow
版权声明:本文标题:google classroom - App script API fails to return Course Materials - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744087277a2588758.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论