Obtain a share UpdateKey from LinkedIn using LinkedIn J and getNetworkUpdates() with Coldfusion

483 views Asked by At

Using the "Network Updates API" example at the following link I am able to post network updates with no problem using client.postNetworkUpdate(updateText).

http://code.google.com/p/linkedin-j/wiki/GettingStarted

So posting works great.. However posting an update does not return an "UpdateKey" which is used to retrieve stats for post itself such as comments, likes, etc. Without the UpdateKey I cannot retrieve stats. So what I would like to do is post, then retrieve the last post using the getNetworkUpdates() function, and in that retrieval will be the UpdateKey that I need to use later to retrieve stats. Here's a sample script in Java on how to get network updates, but I need to do this in Coldfusion instead of Java.

Network network = client.getNetworkUpdates(EnumSet.of(NetworkUpdateType.STATUS_UPDATE));
System.out.println("Total updates fetched:" + network.getUpdates().getTotal());
for (Update update : network.getUpdates().getUpdateList()) {
    System.out.println("-------------------------------");
    System.out.println(update.getUpdateKey() + ":" + update.getUpdateContent().getPerson().getFirstName() + " " + update.getUpdateContent().getPerson().getLastName() + "->" + update.getUpdateContent().getPerson().getCurrentStatus());
    if (update.getUpdateComments() != null) {
            System.out.println("Total comments fetched:" + update.getUpdateComments().getTotal());
            for (UpdateComment comment : update.getUpdateComments().getUpdateCommentList()) {
                    System.out.println(comment.getPerson().getFirstName() + " " + comment.getPerson().getLastName() + "->" + comment.getComment());                         
            }
    }
}

Anyone have any thoughts on how to accomplish this using Coldfusion?

Thanks

2

There are 2 answers

13
Leigh On BEST ANSWER

I have not used that api, but I am guessing you could use the first two lines to grab the number of updates. Then use the overloaded client.getNetworkUpdates(start, end) method to retrieve the last update and obtain its key.

Totally untested, but something along these lines:

<cfscript>
    ... 
    // not sure about accessing the STATUS_UPDATE enum. One of these should work:
    // method 1 
     STATUS_UPDATE = createObject("java", "com.google.code.linkedinapi.client.enumeration.NetworkUpdateType$STATUS_UPDATE");
    // method 2
    NetworkUpdateType = createObject("java", "com.google.code.linkedinapi.client.enumeration.NetworkUpdateType");
    STATUS_UPDATE = NetworkUpdateType.valueOf("STATUS_UPDATE");

    enumSet = createObject("java", "java.util.EnumSet");
    network = yourClientObject.getNetworkUpdates(enumSet.of(STATUS_UPDATE));
    numOfUpdates = network.getUpdates().getTotal(); 
    // Add error handling in case numOfUpdates = 0
    result = yourClientObject.getNetworkUpdates(numOfUpdates, numOfUpdates); 
    lastUpdate = result.getUpdates().getUpdateList().get(0);
    key = lastUpdate.getUpdateKey();
</cfscript>   
0
Tarun Nagpal On

You can also use socialauth library to retrieve updates and post status on linkedin.
http://code.google.com/p/socialauth