1

I am using google api service to access google calender API. Here is my java sample

GoogleCredential credentials = new GoogleCredential.Builder()
                .setTransport(GoogleNetHttpTransport.newTrustedTransport())
                .setJsonFactory(JacksonFactory.getDefaultInstance())
                .setServiceAccountId("")
                .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar.readonly"))
                .setServiceAccountPrivateKeyFromP12File(
                        new File(""))
                .build();
        com.google.api.services.calendar.Calendar client = new com.google.api.services.calendar.Calendar.Builder(GoogleNetHttpTransport.newTrustedTransport(),
                JacksonFactory.getDefaultInstance(), credentials).build();

        Calendar calendar = addCalendar(client);

        private static Calendar addCalendar(com.google.api.services.calendar.Calendar client) throws IOException {
        Calendar entry = new Calendar();
        entry.setSummary("Calendar for Testing 3");
        Calendar result = client.calendars().insert(entry).execute();
        return result;
    }

    Response:
    POST https://oauth2.googleapis.com/token
{
  "error" : "invalid_scope",
  "error_description" : "Invalid OAuth scope or ID token audience provided."
}

From where should I set calendar scope to service account

Pez
  • 1,091
  • 2
  • 14
  • 34

1 Answers1

0

You are already declaring the read only scope.

.setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar.readonly"))

Have you tried adding more to the array?

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449