Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
139 views
in Technique[技术] by (71.8m points)

Get the student´s submission id of a google classroom assignment

I want to return assignments in Google Classrom using

service().courseWork().studentSubmissions().return_(courseId=PASS_HERE_THE_COURSEID, courseWorkId=PASS_HERE_THE_COURSEWORDID, id=PASS_HERE_THE_SUBMISSION_ID)

I have the courseId and the courseWorkId, but don′t know how to get the id=PASS_HERE_THE_SUBMISSION_ID for each student.

Hope someone can help me.

question from:https://stackoverflow.com/questions/65924064/get-the-student%c2%b4s-submission-id-of-a-google-classroom-assignment

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use courses.courseWork.studentSubmissions.list to get a list of student submissions. You just need to provide the courseId and courseWorkId as a path parameter. You may also include additional query parameters in your request.

For example, you want to restrict returned student work to those owned by the student with the specified identifier. You need to set a specific identifier to userId as part of your query parameters

Note: You may also loop all the list of student submission to process each submission before returing it using courses.courseWork.studentSubmissions.return

  • The numeric identifier for the user
  • The email address of the user
  • The string literal "me", indicating the requesting user

Sample Response Body (JSON):

{
  "studentSubmissions": [
    {
      object (StudentSubmission)
    }
  ],
  "nextPageToken": string
}

StudentSubmission contains all the information related to the student submission for the course work including the courseId, courseWorkId, id and userId.

StudentSubmission Resource (JSON):

{
  "courseId": string,
  "courseWorkId": string,
  "id": string,
  "userId": string,
  "creationTime": string,
  "updateTime": string,
  "state": enum (SubmissionState),
  "late": boolean,
  "draftGrade": number,
  "assignedGrade": number,
  "alternateLink": string,
  "courseWorkType": enum (CourseWorkType),
  "associatedWithDeveloper": boolean,
  "submissionHistory": [
    {
      object (SubmissionHistory)
    }
  ],

  // Union field content can be only one of the following:
  "assignmentSubmission": {
    object (AssignmentSubmission)
  },
  "shortAnswerSubmission": {
    object (ShortAnswerSubmission)
  },
  "multipleChoiceSubmission": {
    object (MultipleChoiceSubmission)
  }
  // End of list of possible types for union field content.
}

(UPDATE)

Regarding the error you have encountered when using courses.courseWork.studentSubmissions.return in Apps Script,

GoogleJsonResponseException: API call to classroom.courses.courseWork.studentSubmissions.return failed with error: @ProjectPermissionDenied The Developer Console project is not permitted to make this request.

It occurred because you are trying to modify a course work which is not created on a Developer Console project. Please refer here.

Sample Code:

  var courseId = '2491255xxxxxx';
  var courseWorkId = '2524434xxxxx'; // manually created in classroom.google.com
  
  //1st TRY with error
  var studentSubmissions = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, courseWorkId);
  Logger.log(studentSubmissions.studentSubmissions[0].id);
  //var ret = Classroom.Courses.CourseWork.StudentSubmissions.return({},courseId, courseWorkId, studentSubmissions.studentSubmissions[0].id);
  //Logger.log(ret);



  var assignment =  {
    title: "Test Assignment 3",
    state: "DRAFT",
    assigneeMode: "ALL_STUDENTS",
    workType: "ASSIGNMENT"
  };

  //var newCourseWork = Classroom.Courses.CourseWork.create(assignment, courseId);
  //2nd TRY without error
  var newCourseWorkId = '2618921xxxxx';
  var studentSubmissions2 = Classroom.Courses.CourseWork.StudentSubmissions.list(courseId, newCourseWorkId);
  var ret = Classroom.Courses.CourseWork.StudentSubmissions.return({},courseId, newCourseWorkId, studentSubmissions2.studentSubmissions[0].id);
  Logger.log(studentSubmissions2);
  Logger.log(ret);
  
 Logger.log(Classroom.Courses.CourseWork.get(courseId,newCourseWorkId));

Explanation:

  1. During the first try, I tried to return a student submission course work which was created in https://classroom.google.com/. This case will encounter an error, since I am trying to modify a course work that is not associated with a developer console project. You can check if a course work has an associated developer console project using Classroom.Courses.CourseWork.get(), associatedWithDeveloper property should be true.

  2. On the 2nd try, I created a draft course work first, then modify the created course work in https://classroom.google.com/. Once I finalized the changes and published the course work. I tried to return the student submission course work and it was successful (return should be null/empty). The reason why it succeed is because a developer console project is associated with the course work since I created the course work using Apps Script, hence I could also modify the student submission using Apps Script.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...