问题
As mentioned in the comments below, if only students can turn something in, then I would need to be able to grade and return the assignment even though it had not been turned in yet. To clarify, the assignment was made with the API and I have control over the class and the student.
As mentioned in additional comments below, even if you do not return the assignment, the student will still see the assigned grade, which fulfills the goal of this question. Thus, turn-ins and returns are not needed to grade assignments with the Classroom API.
There are a couple of questions similar to this one, but not as complete and none seem to have concrete answers, so I will try and be as specific as possible. I need to be able to force-turn-in a student's assignment, even though they have not done so yet, and then put a grade, and then return it. With the script below, I am getting two errors.
One, "Invalid JSON payload received. Unknown name "assignment_submission": Cannot find field. (line 15, file "GRADES CLASSROOM")" even though this is in the Classroom reference (https://developers.google.com/classroom/reference/rest/v1/courses.courseWork.studentSubmissions).
Two, when I try and use the "return" method, (second last line of code) it returns the error "Missing name after . operator. (line 17, file "GRADES CLASSROOM")" when I try and save the code, forcing me to comment it out before saving. I think many people have been looking for an answer to how to set this process up.
function returnGrade () {
var submit ={assignedGrade: 80};
var upDate = {updateMask: 'assignedGrade'};
var resource1 = {
assignmentSubmission: {
addAttachments: [{
link:{
url: "URL"
},
}],
},
};
// Classroom.Courses.CourseWork.StudentSubmissions.turnIn(resource1, COURSE ID, WORK ID, "EMAIL");
Classroom.Courses.CourseWork.StudentSubmissions.patch(submit, COURSE ID, WORK ID, "EMAIL", upDate);
// Classroom.Courses.CourseWork.StudentSubmissions.return(resource1, COURSE ID, WORK ID, "EMAIL");
}
In the comments below, the code to set the grade has been resolved. We only need to see how to return the grade.
回答1:
Short answer
Course work submissions (assignments, questions) could only be done by students or by using their credentials. We could uso OAuth for this but if you don't want to use OAuth, then turn in the course work by using the student account, in other words, make a function to be ran by with the student account and make another function to do the the patch / return operations with the teacher / domain administrator account.
It's possible to grade student course work submissions even if they aren't submitted by using
patch
.- Course work submissions can only be returned to students if they were turned if first
Code
The following code added the grades to one student "successfully". At this time I was able to verify that drafGrade was correctly registered on the web UI.
function doPatch(){
var courseId = '6915813348';
var courseWorkId = '11297534926';
var studentSubmissions = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, courseWorkId,{'userId':'someone@gmail.com'});
var id = studentSubmissions['studentSubmissions'][0].id;
var studentSubmission = {
'assignedGrade': 99,
'draftGrade': 80
}
Classroom.Courses.CourseWork.StudentSubmissions.patch(
studentSubmission,
courseId,
courseWorkId,
id,
{
'updateMask':'assignedGrade,draftGrade'
}
);
}
The assignedGrade is visible to the teacher and student on the student work view
The draftGrade is visible to the teacher on the submissions view
Notes
I made some research and tests and found some "interesting things"
The error message
"Missing name after . operator. (line 17, file "GRADES CLASSROOM")"
Looks to be caused by the use of return
in
Classroom.Courses.CourseWork.StudentSubmissions.return(resource1, COURSE ID, WORK ID, "EMAIL");
Reference: Google App Script
The error occurs because return
is a JavaScript keyword. The alternative syntax is
Classroom.Courses.CourseWork.StudentSubmissions["return"](resource1, COURSE ID, WORK ID, "EMAIL")
But this requires that the related student submitted the course work otherwise the Classroom API will throw a Failed Precondition error.
I don't have a complete answer yet, but it's important to bear in mind that some tasks depend on the user class role that could be teacher or student but not both for the same course.
So in order to make an assignment submission the corresponding method should be called someway on behalf the corresponding student and in order to return an assignment this should be called someway on behalf a class teacher.
References
From Method: courses.courseWork.studentSubmissions.turnIn
This may only be called by the student that owns the specified student submission.
From Method: courses.courseWork.studentSubmiss.return
Only a teacher of the course that contains the requested student submission may call this method.
来源:https://stackoverflow.com/questions/48480059/google-apps-script-to-turn-in-grade-and-return-a-google-classroom-assignment