Connecting Java with Google Calendar - java

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.

Related

sugarcrm editview coding help for newbi

I have an older version of sugarcrm 4.5 running.
Dont brake that aint broken.
I have a script i wrote that adds 30 days from current date to expected close date when creating a new opportunity, but the problem is everytime you edit the opportunity it adds 30 days, and not just when its is new. How do i tel Sugar to only look for new. this is in editview.php not a logic hook as i want to display the date in the field when creating.
Heres my code
var currentTime = new Date();
document.getElementsByName('date_closed')[0].value = (year = currentTime.getFullYear())+'-'+(month = currentTime.getMonth() + 2)+'-'+(day = currentTime.getDate());
regards
This should be done with a before save logic hook - you can test to see if the record has an id in the hook. If it has no id then you can assume its a new record.
More information on logic hooks can be found here (you are using a very old version of SugarCRM so not everything in this documentation will apply)
http://developers.sugarcrm.com/docs/OS/5.2/-docs-Developer_Guides-Developer_Guide_5.2-DevGuide%205.2.1.47.html

How to retrieve the event start time in google calendar using the java 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?

All Event listing on specified date in Google Calender api (V3) in java?

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.

Google Calendar API w/ Java - Get events only for the default calendar, ignoring the holidays

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();

How do I write Facebook apps in Java?

I have looked in vain for a good example or starting point to write a java based facebook application... I was hoping that someone here would know of one. As well, I hear that facebook will no longer support their java API is this true and if yes does that mean that we should no longer use java to write facebook apps??
There's a community project which is intended to keep the Facebook Java API up to date, using the old official Facebook code as a starting point.
You can find it here along with a Getting Started guide and a few bits of sample code.
Facebook stopped supporting the official Java API on 5 May 2008 according to their developer wiki.
In no way does that mean you shouldn't use Java any more to write FB apps. There are several alternative Java approaches outlined on the wiki.
You might also want to check this project out; however, it only came out a few days ago so YMMV.
I write an example using facebook java api
It use FacebookXmlRestClient in order to make client request and print
all user infos
http://programmaremobile.blogspot.com/2009/01/facebook-java-apieng.html
BatchFB provides a modern Java API that lets you easily optimize your Facebook calls down to a minimum set:
http://code.google.com/p/batchfb/
Here's the example taken from the main page of what you can effectively do in a single FB request:
/** You write your own Jackson user mapping for the pieces you care about */
public class User {
long uid;
#JsonProperty("first_name") String firstName;
String pic_square;
String timezone;
}
Batcher batcher = new FacebookBatcher(accessToken);
Later<User> me = batcher.graph("me", User.class);
Later<User> mark = batcher.graph("markzuckerberg", User.class);
Later<List<User>> myFriends = batcher.query(
"SELECT uid, first_name, pic_square FROM user WHERE uid IN" +
"(SELECT uid2 FROM friend WHERE uid1 = " + myId + ")", User.class);
Later<User> bob = batcher.queryFirst("SELECT timezone FROM user WHERE uid = " + bobsId, User.class);
PagedLater<Post> feed = batcher.paged("me/feed", Post.class);
// No calls to Facebook have been made yet. The following get() will execute the
// whole batch as a single Facebook call.
String timezone = bob.get().timezone;
// You can just get simple values forcing immediate execution of the batch at any time.
User ivan = batcher.graph("ivan", User.class).get();
You might want to try Spring Social. It might be limited in terms of Facebook features, but lets you also connect to Twitter, LinkedIn, TripIt, GitHub, and Gowalla.
The other side of things is that as Facebook adds features some of the old API's might break, so using a simpler pure FB api (that you can update when things don't work) might be a good idea.
This tutorial will literally step you through everything you need to do: http://ocpsoft.org/opensource/creating-a-facebook-app-setup-and-tool-installation/
It comes in 3 parts. The other 2 are linked from there.

Categories

Resources