You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API向Google Classroom提交作业并更新学生作业完成状态?

Hey there! Let’s walk through exactly how to handle both syncing assignment completion status to Google Classroom and submitting assignments via the API—since you’ve already got the basics down, this should fit right into your existing integration.

Syncing Student Assignment Completion Status to Google Classroom

When a student marks an assignment as complete in your app, you need to update their corresponding submission record in Google Classroom to reflect that. Here’s what you need to do:

  • Use the courses.courseWork.studentSubmissions.patch API: This lets you update specific fields of a student’s submission without overwriting the entire record.
  • Required IDs: You’ll need three key values: the courseId (your target Classroom ID), courseWorkId (the ID of the assignment in question), and userId (the student’s Google account ID—use me if you’re acting on behalf of the currently authenticated student).
  • Update the state: In your request body, set the state field to TURNED_IN to mark the assignment as submitted. If you’re handling teacher feedback later, you can also use RETURNED when sending graded work back to the student.
  • Permissions: Make sure your app has the classroom.coursework.students OAuth scope (or classroom.coursework.me if you’re only acting on behalf of the authenticated user).

Example request structure (simplified):

PATCH https://classroom.googleapis.com/v1/courses/{courseId}/courseWork/{courseWorkId}/studentSubmissions/{userId}
Content-Type: application/json

{
  "state": "TURNED_IN"
}

If you need to update statuses for multiple students at once, use courses.courseWork.studentSubmissions.batchUpdate instead—it’s much more efficient than making individual patch requests.

Submitting Assignments to Google Classroom via API

There are two main scenarios here, each with a dedicated API:

Scenario 1: Submit an assignment on behalf of a student

If you want to directly mark a student’s assignment as submitted (similar to them clicking "Turn in" in Classroom), use the courses.courseWork.studentSubmissions.turnIn API. This is a straightforward action that sets the submission state to TURNED_IN in one step.

  • Required parameters: Same as above—courseId, courseWorkId, and userId.
  • Permissions: Use classroom.coursework.me for student-authenticated requests, or classroom.coursework.students if you’re acting as an admin/teacher.

Example request:

POST https://classroom.googleapis.com/v1/courses/{courseId}/courseWork/{courseWorkId}/studentSubmissions/{userId}:turnIn
Content-Type: application/json

{}

Scenario 2: Create a new submission with attachments

If you need to upload files or links as part of the submission (like a student uploading a document from your app), use the courses.courseWork.studentSubmissions.create API first to create the submission record, then call turnIn to mark it as complete.

In the request body, specify the assignmentSubmission field with an attachments array—you can include Drive files, links, or other supported attachment types.

Example request (creating a submission with a Drive file):

POST https://classroom.googleapis.com/v1/courses/{courseId}/courseWork/{courseWorkId}/studentSubmissions
Content-Type: application/json

{
  "userId": "student@example.com",
  "assignmentSubmission": {
    "attachments": [
      {
        "driveFile": {
          "id": "123abcXYZ"
        }
      }
    ]
  }
}
Quick Notes to Avoid Headaches
  • Always verify the current submission state with courses.courseWork.studentSubmissions.get before making updates—this prevents accidental overwrites or duplicate submissions.
  • Make sure your OAuth token has the correct scopes; missing permissions are the most common cause of API errors here.
  • Classroom sometimes caches submission data, so if you don’t see updates immediately, give it a minute to sync.

内容的提问来源于stack exchange,提问作者Innocent Criminal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:36:43