Alexsandro Novaes
Alexsandro Novaes

Reputation: 41

Code: 403 Message: The caller does not have permission

I'm using the Google Classroom API to integrate my business system into Google Classroom. I can create and list courses using a service account. But always using the OwnerId = "me". All the courses that I'm creating are with the client_id of my service account. If I try to create with some other ownerID I get the error:

Code: 403 Message: The caller does not have permission Domain: global Reason: forbidden Status: PERMISSION_DENIED

Any tips on how to solve this problem?

Thank you.

Upvotes: 4

Views: 5110

Answers (1)

Faisal Asif
Faisal Asif

Reputation: 209

You must use email to impersonate a user while creating credentials before you create an instance for ClassRoom

.setServiceAccountUser("UserEmail")

Sample Code is attached below

final NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
                GoogleCredential credential = new GoogleCredential.Builder()
                        .setTransport(httpTransport)
                        .setJsonFactory(JSON_FACTORY)
                        .setServiceAccountId("class-room-service-account-id")
                        .setServiceAccountPrivateKeyFromP12File(new File("/Credentials/MyProject.p12"))
                        .setServiceAccountScopes(SCOPES)
                        .setServiceAccountUser("UserEmail") //There should be the Email for the user you are creating course
                        .build();

                final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
                ClassRoom service = new Classroom.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                        .setApplicationName(APPLICATION_NAME)
                        .build();

After this using OwnerId "me" will create course for the user impersonated.

Upvotes: 0

Related Questions