I need some help, I have an application running on GAE and this read some information from a internet page and put inside my calendar as events.
And after google changed the API to v3, I can't connect using my own gmail. Before that I was using CalendarService passing the credentials (email and app password).
Now I need to use another email created from OAuth2, but when I created an event, this event was created to "primary" calendar of this new email.
How can I connect using my own email and put these events inside the correct calendar and not the primary one?
Thanks for your help and time. Celso
EDIT
I tried to read the calendar list but it's empty. I think that it's because the email that I use to connect using OAuth2, but I'm not sure about it.
Take a look, please.
Thx for your time.
protected Calendar getCalendarService() throws GeneralSecurityException, IOException {
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport(); JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance(); Credential credential = new GoogleCredential.Builder() .setTransport(httpTransport) .setJsonFactory(jsonFactory) .setServiceAccountId("xxxxxxxx@developer.gserviceaccount.com") .setServiceAccountPrivateKeyFromP12File(new File("cert.p12")) .setServiceAccountScopes(Collections.singleton(CalendarScopes.CALENDAR)) .build(); return new Calendar.Builder(httpTransport, jsonFactory, credential).setApplicationName("appname").build(); }
While inserting event, if you pass 'primary' in the Events: insert,
Event createdEvent = service.events().insert('primary', event).execute();
then event gets inserted into the primary calendar.
If you want to create event not to the primary one, then create secondary calendar. Here is the link . You can get the calendar list from CalendarList: list where you can see the calendar ID of the primary and secondary calendars. Then when inserting the event, pass the secondary calendar ID instead of 'primary'in Events: insert. Let me know if you have any questions.
After more hours of search I found a possible solution that I describe as follow:
I solved my problem. Thanks.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.