First, let me explain what I am trying to do, as this is a two part question.
I am building a JAX-RS service that internally authenticates with a Google account via
OK, so I have been playing around with this and have got past the 401 error, but I am now hitting a 403. However, I will detail the code I have written that at least answers the 401 problem.
I did not change any of the service account settings or re-generate any of the keys etc, that is all the same.
What has change is some of the code, and I upgraded to v3r20lv1.12.0-beta of the Calendar API.
The code below, as detailed above in the OP, remains the same, i.e.:
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
private static final JsonFactory JSON_FACTORY = new JacksonFactory();
.
.
.
GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("284XXXXXXXX@developer.gserviceaccount.com")
.setServiceAccountScopes(CalendarScopes.CALENDAR)
.setServiceAccountPrivateKeyFromP12File(new File("D:/3cd8XXXXXXXXXXXXXXXXXXXXXXXXXXXXXd635e-privatekey.p12"))
.build();
The code to get a handle for the Calendar has changed, but this was forced by an API change:
Calendar calendar = new Calendar(HTTP_TRANSPORT, JSON_FACTORY, credential);
At this point, I can iterate through my calendar and see the events, by running the following code (this prints an event summary):
Events events = calendar.events().list(CALENDAR_ID).execute();
for (Event event : events.getItems())
{
System.out.println(event.getSummary());
}
But, if I try and update an event, I get a 403 Forbidden error. I will raise a separate thread for this, and will link the two threads together.
Thanks to all for your help!
EDIT: here is the new thread.