Я пытаюсь создать событие с сервера, используя java.
Вот мой код для того же.
private static final String APPLICATION_NAME = "Google Calendar API Java Quickstart";
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
private static final String TOKENS_DIRECTORY_PATH = "tokens";
private static final List<String> SCOPES = Collections.singletonList(CalendarScopes.CALENDAR);
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";
private static final String projfilepath = "/quickstart-foxmatrix.json";
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws Exception {
// Load client secrets.
InputStream in = CalendarQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
if (in == null) {
throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
}
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(HTTP_TRANSPORT, JSON_FACTORY,
clientSecrets, SCOPES)
.setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
.setAccessType("offline").build();
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(9000).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
}
public static void main(String... args) throws Exception {
// Build a new authorized API client service.
final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
InputStream in = CalendarQuickstart.class.getResourceAsStream(projfilepath);
GoogleCredential credential = GoogleCredential.fromStream(in)
.createScoped(Collections.singleton(CalendarScopes.CALENDAR));
Calendar service = new Calendar.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName(APPLICATION_NAME).build();
CalendarQuickstart obj = new CalendarQuickstart();
obj.createEvent(service);
}
public String createEvent(Calendar service) throws IOException {
Event event = new Event().setSummary("New Event")
.setDescription("A chance to hear more about Google's developer products.");
DateTime startDateTime = new DateTime("2020-02-04T09:00:00-07:00");
EventDateTime start = new EventDateTime().setDateTime(startDateTime);
event.setStart(start);
DateTime endDateTime = new DateTime("2020-02-04T17:00:00-07:00");
EventDateTime end = new EventDateTime().setDateTime(endDateTime);
event.setEnd(end);
EventAttendee[] attendees = new EventAttendee[] {
new EventAttendee().setEmail("hanil.kathuria@innovationm.com"),
new EventAttendee().setEmail("jijo.mathew@innovationm.com"), };
event.setAttendees(Arrays.asList(attendees));
EventReminder[] reminderOverrides = new EventReminder[] {
new EventReminder().setMethod("email").setMinutes(24 * 60),
new EventReminder().setMethod("popup").setMinutes(10), };
Event.Reminders reminders = new Event.Reminders().setUseDefault(false)
.setOverrides(Arrays.asList(reminderOverrides));
event.setReminders(reminders);
String calendarId = "primary";
event = service.events().insert(calendarId, event).execute();
System.out.printf("Event created: %s\n", event.getHtmlLink());
event.getHangoutLink();
return event.getHtmlLink();
}
Я использую учетные данные своей учетной записи службы из json файл.
Я использую клиентскую библиотеку Google для вызова API.
Я также проверил свою панель управления, и ограничение для вызова API составляет 100 / se c. и для вызова API не отображается трафик c. Тем не менее, когда я пытаюсь создать событие, оно показывает превышение лимита использования.
полная ошибка
Исключение в теме "main" com.google.api.client.googleapis. json .GoogleJsonResponseException: 403 Forbidden {"code": 403, "errors": [{"domain": "useLimits", "message": "Превышены пределы использования календаря.", "Reason": "quotaExceeded"}], "message": "Превышены пределы использования календаря." }