Monday, November 30, 2009

Updating your Lotus Connections microblog programmatically

View Comments

This post is very techie. It comes as a reader recently asked me to share the code that I use to programmatically update my microblog (or status) in Lotus Connections. The following code is using Java and Abdera, but should be easily portable to other platforms like Adobe AIR. The Lotus Connections Profiles API documentation was helpful when I was trying to figure this out.

  1. Initialize the Abdera library
    // Initialize the Atom Client to update the status in Connections
    Abdera abdera = new Abdera();
    AbderaClient client = new AbderaClient(abdera);
    AbderaClient.registerTrustManager();
    try
    {
    client.addCredentials("http://connections.tap.ibm.com", null, null, new UsernamePasswordCredentials(username, password));
    }
    catch (URISyntaxException e)
    {
    e.printStackTrace();
    }
    
  2. Create the Atom entry to post to Lotus Connections


    Parser parser = abdera.getParser();
    String urlText = "https://connections.tap.ibm.com/profiles/atom/mv/thebuzz/entry/status.do?email=" + username;
    // Create the Atom entry with the new status message
    Entry status = abdera.newEntry();
    status.addCategory("http://www.ibm.com/xmlns/prod/sn/type", "entry", null);
    status.addCategory("http://www.ibm.com/xmlns/prod/sn/message-type", "status", null);
    message = StringEscapeUtils.escapeHtml(message);
    status.setContent(message);


  3. Post the Atom entry
    // Send the new status message to Connections
    ClientResponse response = client.put(urlText, status);
    
  4. Check the return code
    if (response.getType() == ResponseType.SUCCESS)
    {
    // yipee
    System.out.println("woo hoo");
    }
    else
    {
    // WTH?
    System.out.println("oh no!");
    }
    

Hope this helps.

blog comments powered by Disqus