Google Classroom API: Authentication Scope Error When Adding New Course

I’m hitting a snag while trying to add a new course using the Google Classroom API. The error message I’m getting is about insufficient authentication scopes. Here’s what the error looks like:

{
  "code": 403,
  "errors": [{
    "domain": "global",
    "message": "Request had insufficient authentication scopes.",
    "reason": "forbidden"
  }],
  "message": "Request had insufficient authentication scopes.",
  "status": "PERMISSION_DENIED"
}

I’ve set up an AsyncTask to handle the API call, but I’m not sure if I’m doing it right. The course creation part looks like this:

Course newCourse = new Course()
    .setName("Biology 101")
    .setSection("Morning Session")
    .setDescriptionHeading("Intro to Biology")
    .setDescription("Explore the basics of life sciences through lectures and hands-on labs.")
    .setRoom("Lab 3")
    .setOwnerId("BioTeacher")
    .setCourseState("ACTIVE");

newCourse = classroomService.courses().create(newCourse).execute();

I’m confused about what to use for the ownerId. Any ideas on what might be causing this authentication issue or how to fix it? Thanks for any help!

hey LeoNinja22, sounds like a tricky one! Have u checked ur OAuth scopes? Make sure u’ve got ‘https://www.googleapis.com/auth/classroom.courses’ in there. For ownerId, use the teacher’s email address. Also, regular Google accounts can’t make courses - gotta be a Workspace for Education one. lemme know if u need more help!

The authentication scope error you’re encountering is a common issue when working with the Google Classroom API. To resolve this, ensure you’ve included the ‘https://www.googleapis.com/auth/classroom.courses’ scope in your OAuth 2.0 credentials. This scope is essential for course creation.

Regarding the ownerId, it should be the email address of the teacher who will own the course. Make sure you’re using a valid Google Workspace for Education account, as standard Google accounts lack the necessary permissions to create courses.

Your course creation code looks correct, but the issue likely lies in how you’re setting up the classroomService object. Double-check your credential initialization and ensure you’re using the correct OAuth flow for your application type (web, installed, or service account).

If the problem persists, review your Google Cloud Console project settings to confirm that the Classroom API is enabled and that your OAuth consent screen is properly configured.

Hey there, LeoNinja22! :wave:

I’ve run into similar authentication issues with the Google Classroom API before. It can be a bit tricky to navigate at first!

Have you double-checked your OAuth 2.0 scopes? For creating courses, you typically need the ‘https://www.googleapis.com/auth/classroom.courses’ scope. Sometimes it’s easy to miss including all the necessary scopes when setting up the credentials.

About the ownerId - that’s usually the email address of the Google account that will own the course. Are you using the correct email for the teacher who should be the owner?

Another thing to consider: are you testing this with a Google Workspace for Education account? Regular Google accounts don’t have permission to create courses, even with the right scopes.

I’m curious - how are you initializing the classroomService object? That might give us some clues too.

Let me know if any of this helps or if you need more info. We can dig deeper into this together! :blush: