2

I want to use Google Classroom Java API in Tomcat Server as a REST API.

  1. I want the client-side code to generate an access token and refresh token and pass them to the REST API endpoints.
  2. The REST API then use the above token to call the following code to get the list of Courses: objectOf(Classroom).courses().list().setPageSize(100).execute();

I am creating the Classroom as follows, where .getCredentials() uses GoogleAuthorizationCodeFlow.Builder to create the credential required, but it opens a browser window to authorize the user and get the token. This doesn't work for me.

NetHttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
    Classroom classRoom = new Classroom.Builder(httpTransport, JSON_FACTORY, getCredentials(httpTransport))
            .setApplicationName(APPLICATION_NAME).build();
Christian König
  • 3,437
  • 16
  • 28

1 Answers1

0

I understand that you want to receive access and refresh tokens to later use them in Classroom; and you want to run this operation from a server. If that is correct, you would need to login as your account to prove your identity and receive the credentials, but there are some alternatives.

Since you are going to execute the code from a server you could follow these steps to create your credentials. Those credentials need to be saved in your work folder once and they can be read on every run.

Alternatively, you could create a service account and use it to reach your goals if you want to interact with Classroom as a different user of your organization. Please, remember to activate domain-wide delegation for this step. Don't hesitate to write back if you have some questions.

Jacques-Guzel Heron
  • 2,480
  • 1
  • 7
  • 16