Код: Выделить всё
public static final List< String > SCOPES = new ArrayList();
static {
SCOPES.add( CalendarScopes.CALENDAR );
SCOPES.add( DriveScopes.DRIVE_READONLY );
SCOPES.add( SheetsScopes.SPREADSHEETS );
};
public GoogleCalendarUtilities( ) throws Exception {
final String JSON_TOKEN = """
{
REDACTED
}
""";
GoogleServiceAccountAuthenticationUtilities googleServiceAccountAuthenticationUtilities = new GoogleServiceAccountAuthenticationUtilities();
HttpRequestInitializer httpRequestInitializer = googleServiceAccountAuthenticationUtilities.getRequestInitializer( JSON_TOKEN ,
Constants.SCOPES );
NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
calendarService = new Calendar.Builder( HTTP_TRANSPORT , JSON_FACTORY , httpRequestInitializer )
.setApplicationName( UUID.randomUUID().toString() )
.build();
}
/**
* Returns a list of CalendarListEntries. You can get the calendar's "summary" and "id" from this object.
* Summary is the name you see on the calendar's web page. Id is the key for accessing the calendar.
* @return
* @throws IOException
*/
public List< CalendarListEntry > getCalendarListEntries() throws IOException {
CalendarList calendarList = calendarService.calendarList().list().setPageToken( null ).execute();
return calendarList.getItems();
}
Я знаю, что OAuth 2 является лучшим решением, но меня интересует сервис-сервис, если это вообще возможно.
Подробнее здесь: https://stackoverflow.com/questions/798 ... ce-account
Мобильная версия