Reputation: 1
private final String clientSecret = "<my_client_secret>";
private final String clientID = "<my_client_id>.apps.googleusercontent.com";
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
//Access token
private Credential credentials = new GoogleCredential.Builder()
.setTransport(new NetHttpTransport())
.setJsonFactory(new JacksonFactory())
.setClientSecrets(clientID, clientSecret)
.build();
Calendar service = new Calendar.Builder(httpTransport, jsonFactory, credentials)
.setApplicationName("Calendar")
.build();
public PersonalCalendar() throws GeneralSecurityException, IOException {
}
public void getGoogleCalendarList() throws IOException {
DateTime now = new DateTime(System.currentTimeMillis());
Events events = service.events().list("primary").setMaxResults(10)
.setTimeMin(now)
.setOrderBy("startTime")
.setSingleEvents(true)
.execute();
List<Event> eventsList = events.getItems();
if (eventsList.size() == 0) {
System.out.println("No upcoming events found.");
} else {
System.out.println("Upcoming events");
for (Event event : eventsList) {
DateTime start = event.getStart().getDateTime();
if (start == null) {
start = event.getStart().getDate();
}
System.out.printf("%s (%s)\n", event.getSummary(), start);
}
}
}
This is my PersonalCalendar.class on my Spring server. I try to obtain my Events from my Google-Calendar. I already have made a ServiceAccount and gave access to my Calendar. My Error Message:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden { "code" : 403, "errors" : [ { "domain" : "usageLimits", "message" : "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "reason" : "dailyLimitExceededUnreg", "extendedHelp" : "https://code.google.com/apis/console" } ], "message" : "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup." }
I also don't understand what list("primary") does by the creation of my Event object. Can someone please explain this to me? And what do i have to do to get my Events from my calendar?
Upvotes: 0
Views: 388
Reputation: 115
It looks like you are not handling the authentication properly. Judging by your code I would guess that you read this: https://developers.google.com/google-apps/calendar/quickstart/java
I cannot see that you are reading your credentials file (client_secret.json
in the guide) somewhere. You can generate this file in the google developer console.
I also don't understand what list("primary") does by the creation of my Event object. Can someone please explain this to me?
You are not creating an event here, you are listing the next 10 events from your service accounts primary calendar.
Upvotes: 1