1

I am trying to get access to my google calendar via google credentials.

 GoogleCredential credentials = new GoogleCredential.Builder().setTransport(httpTransport)
                .setJsonFactory(jsonFactory)
                .setServiceAccountId("xxx@developer.gserviceaccount.com")
                .setServiceAccountScopes(Arrays.asList("https://www.googleapis.com/auth/calendar"))
                .setServiceAccountPrivateKeyFromP12File(new File("Disk:\\xxx-privatekey.p12"))
                .setServiceAccountUser("xxx@gmail.com").build();

        Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
                .setApplicationName("CalendarTest").build(); 

but when I want to do smth with a calendar like

com.google.api.services.calendar.model.Calendar calendar = service.calendars().get("primary").execute();

        System.out.println(calendar.getSummary());

I get an error

com.google.api.client.auth.oauth2.TokenResponseException: 400 Bad Request
{
  "error" : "access_denied",
  "error_description" : "Requested scopes not allowed: https://www.googleapis.com/auth/calendar"
}

0 Answers0