Just an another blog about software development, configuration and usual stuff ...

Create Calendar Resource using Google Data Java API (gdata-java-client)

Many enterprises and educational units want to track of their resources like conference rooms, projectors, etc. This is very important from enterprise point of view. Luckily Google introduced Calendar Resources in Premier and Education Edition.

The question comes how to manage resources from API. Calendar Resource Management at Google explains this, however not in java.

Following is the code snippet which shows how to create resources using Java GData client API.

try {
  String application_name = "APPLCATION_NAME";
  String admin_email = "APPS_ADMIN_EMAIL";
  String admin_password = "APPS_ADMIN_PASSWORD";
  String domain_name = "APPS_DOMAIN_NAME";
  
  AppsPropertyService service = new AppsPropertyService(application_name);
  service.setUserCredentials(admin_email,admin_password));

  URL feedUrl = 
    new URL("https://apps-apis.google.com/a/feeds/calendar/resource/2.0/" + domain_name);

  GenericEntry resourceEntry = new GenericEntry();
  resourceEntry.declareExtensions(service.getExtensionProfile());
  resourceEntry.addProperty("resourceId", "CAL_RESOURCE_ID");
  resourceEntry.addProperty("resourceCommonName", "CAL_RESOURCE_COMMON_NAME");
  resourceEntry.addProperty("resourceDescription", "CAL_RESOURCE_DESC");
  resourceEntry.addProperty("resourceType", "CAL_RESOURCE_TYPE");
  
  service.insert(feedUrl, resourceEntry);

  resourceEntry = null;
  feedUrl = null;
  service = null;
} catch (MalformedURLException ex) {
  ex.printStackTrace();
} catch(AuthenticationException ex) {
  ex.printStackTrace();
} catch (AppsForYourDomainException ex) {
  ex.printStackTrace();
} catch (IOException ex) {
  ex.printStackTrace();
} catch (ServiceException ex) {
  ex.printStackTrace();
}

| More

One Response

  1. gravatar Fer Troya says:

    May be it be worth to mention that you need the appsforyourdomain jar provided with gdata in your classpath for this to work.

    I wonder how this is done under Google API v3 set.

Leave a Reply

Archives

Categories