4

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.

  • You may refer with this [thread](https://groups.google.com/forum/#!topic/google-apps-manager/ZvxBK2U9otE). Make sure that the account you're trying to add is in the same domain as the course. Also, as stated [here](https://www.hdgem.com/2017/04/how-to-fix-google-cloud-caller-does-not.html), you need to double check your current active account and make sure your current active account have that permission. Or else you need to go to your Google cloud console to assign the permission to your current active account or you need to switch your account. – abielita Apr 30 '17 at 18:27
  • 1
    Thanks. Account is in the same domain as the course. I tried to set permission using Google Admin console. Still getting error Code: 403 Message: The caller does not have permission Domain: global Reason: forbidden Status: PERMISSION_DENIED – Alexsandro Novaes May 02 '17 at 19:03
  • I get the same error I'm trying to delete a teacher from a course – Diego Apr 20 '18 at 19:47

1 Answers1

0

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.

Faisal Asif
  • 199
  • 2
  • 15