How can I empty a trash of a calendar via Google services?
I'm calling google services in Java (com.google.api.services.calendar.Calendar) but I need to empty trash after I deleted events.
I think I have found the only way to solve this problem:
Create a temporary calendar
Move into this calendar all events that I have to delete
Delete the temporary calendar
Like this code:
Calendar entry = new Calendar();
entry.setSummary("MyTrashCalendar");
Calendar result = client.calendars().insert(entry).execute();
...
Event updatedEvent = client.events().move('currentCalendarId', "eventId", "destinationCalendarId").execute();
...
client.calendars().delete(calendar.getId()).execute();
I hope this helps
Related
I have created a public calendar folder, but none of the users see it. It should be shared with others.
This is my code:
FolderView fv = new FolderView(50);
fv.setTraversal(FolderTraversal.Deep);
FindFoldersResults f = service.findFolders(WellKnownFolderName.PublicFoldersRoot, fv);
The problem is it throws java.lang.NullPointerException and
microsoft.exchange.webservices.data.EWSHttpException: Connection not established
When I change it to WellKnownFolderName.Root or any other constant like Calendar or Inbox it is working fine. I can review contents with Outlook though.
How can I access public calendar folder with Java if I don't see it and don't know the ID as well?
If you know the email address of the person / resource with the shared folder, then this might work
//Create a inclusive view
FolderView fv = new FolderView(100);
fv.setTraversal(FolderTraversal.Deep);
//Find ID of parent calendar
FolderId sharedFolderId = new FolderId(WellKnownFolderName.Calendar, new Mailbox("email.address#of-thing-sharing-calendar"));
//Find children of that calendar
FindFoldersResults findResults = service.findFolders(sharedFolderId, fv);
There is a working example here: Can't connect to (EWS) Public Calendar Folder Java It contains a sample java class that should compile and run, using the Java EWS API
I have searched a lot and couldnt find the info that i am looking for. I am trying out a google calendar application in google app engine with java. I am unable to figure out how to retrieve the start time of a calendar event. The 'when' field in the CalendarEventEntry class does not exist ( i checked older posts and tried to follow those answers). The getTimes() method returns a list of DateTime entries but i am not sure what those are. Here is a snippet of my code -
CalendarEventFeed resultFeed = service.getFeed(Films_Url, CalendarEventFeed.class);
for (int i = 0; i < resultFeed.getEntries().size(); i++)
{
CalendarEventEntry entry = resultFeed.getEntries().get(i);
Entity Film = new Entity("Films_and_Movies",Film_and_Movie_key);
Film.setProperty("title",entry.getTitle().getPlainText());
Film.setProperty("time",entry.getUpdated().toUiString());
DatastoreService datastorE = DatastoreServiceFactory.getDatastoreService();
datastore.put(Film);
}
entry.getUpdated() does return a DateTime object but it is the time when the event was updated, not the start time. I tried using entry.when.startDate but 'when' does not exist in the CalendarEventEntry class as I said earlier. I tried using EventEntry instead of CalendarEntry but I dont think the former does not exist anymore in recent updates. Can someone please guide me?
what I want to do is get all the events in a given google calendar for a given date.
Now we can get the event listing pretty easily using the following code
public Events getAllEvent()
{
Events events= null ;
try {
events = service.events().list(this.calendarID).execute();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return events ;
}
How should I convert this function so that it will give only event on that day which i specify. I tried a lot of way but in version 3 it's not working the way it use to in v2.
Any suggestion. Please Remeber that we are talking about google calender Api version 3.
Hi ya i found the answer to my ques so updating here for others.
This can be done. Though we do not have direct way we can do it using query parameter. Let say if we wanted events feed from today onwards and not earlier than today. Then we can do this.
Events events = service.events().list(calendarID).setTimeMin("2012-01-01T00:00:00Z").execute();
instead of
events = service.events().list(this.calendarID).execute();
which just give us all the feeds from way back till 2031.
For getting feeds in between dates use setTimemin and setTimeMax together
Hope this help someone cheers...
Listed below is the code to use the Calendar service for v3 of the Google API utilizing Oauth2. I am posting it, since it is documented incorrectly by Google on their site.
Calendar service3 = new Calendar(transport, jsonFactory, accessProtectedResource);
com.google.api.services.calendar.model.Calendar calendar = service3.calendars().get("primary").execute();
com.google.api.services.calendar.model.Events events = service3.events().list("primary").execute();
Sameer currently the API doesn't includes this feature. But you can make a feature request here Apps Apis issue tracker.
You shall get some positive reply soon as it is monitored by Google engineers themselves.
What I am trying to do is get a list of all the events in the default calendar only? I don't want any other calendars' events included, i.e., holidays.
I am using the ".../feeds/username/default/full" and doing a query for all events from 1 month ago to forever. I have two events that I have created but I get a feed with 25 entries. My two events first and then 23 holidays. I really don't them to be included at all but if them MUST be there, how do I detect them. The only thing I can find is the eTag for my two events is different from the holiday ones. But I can't just say get all the events from the first Etag I encounter because the default calendar may not have any events so the first one would be holidays.
Any help would be appreciated.
This can be done with a few lines of code using the latest version of the Google Calendar API. All you need to do is pull the events for the primary calendar, as documented here:
http://code.google.com/apis/calendar/v3/using.html#retrieving_events
The code you need is:
Events events = service.events().list("primary").execute();
while (true) {
for (Event event : events.getItems()) {
System.out.println(event.getSummary());
}
String pageToken = events.getNextPageToken();
if (pageToken != null && !pageToken.isEmpty()) {
events = service.events().list("primary").setPageToken(pageToken).execute();
} else {
break;
}
}
I wonder what version of the Calendar API you are using? In v3 I am able to all my events without getting the holidays. I added some more code examples, since the Google documentation is incorrect for connecting to the Calendar V3 API though Oauth2 for Java.
Use the code listed in the other post to loop though the Calendar events after the Oauth is setup and the Calendar is initialized. You probably can, but do not need to declare the events API. I just call it from the Calendar service(3). Note the Calendar ID I have listed is "Primary."
Calendar service3 = new Calendar(transport, jsonFactory, accessProtectedResource);
com.google.api.services.calendar.model.Calendar calendar = service3.calendars().get("primary").execute();
com.google.api.services.calendar.model.Events events = service3.events().list("primary").execute();
I'm relatively new to Java, so I have little to no idea where to even start with this one. I'm writing a scheduling application using Java and google calendars. On my google account I have a bunch of calendars with people's schedules on them. I need to access these calendars through java and insert the person's free / busy information into arrays like so:
//User 1
int[][] swift_schedule = new int[5][6];
//1 = busy, 0 = free
//Monday
swift_schedule[0][0] = 0; //9-11
swift_schedule[0][1] = 1; //11-1
swift_schedule[0][2] = 1; //1-3
swift_schedule[0][3] = 1; //3-5
swift_schedule[0][4] = 1; //5-7
swift_schedule[0][5] = 1; //7-9
//Tuesday
swift_schedule[1][0] = 0; //9-11
swift_schedule[1][1] = 0; //11-1
swift_schedule[1][2] = 0; //1-3
etc....
If I were using PHP, I would get a url for the XML feed and just parse the data out of it, but with JAVA I don't even know where to start. Can anyone point me in the right direction? Tutorials, code snippets, and other hints would be greatly appreciated!
cheers,
Mike
You don't have to do the parsing when there is a Java API for it, simply use it and query for the calendar events you want.
With DateTime and CalendarQuery you can query for events in a specific time interval (your use case: to get events in a give day).
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2006-03-16T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2006-03-24T23:59:59"));
Google Calendar allows client
applications to view and update
calendar events in the form of Google
Data API feeds. Your client
application can use the Google
Calendar Data API to create new
events, edit or delete existing
events, and query for events that
match particular criteria.