我正试图通过谷歌凭证访问我的谷歌日历。
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();
但是当我想用
这样的日历做smth时com.google.api.services.calendar.model.Calendar calendar = service.calendars().get("primary").execute();
System.out.println(calendar.getSummary());
我收到错误
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"
}