Connector of the Week: Using the LinkedIn API

motif

Of all the professional networks available LinkedIn has clearly taken the lead with more than 120 million members. Do you use LinkedIn? Most likely you do! That’s why we thought it’s important to have a Connector to interact with LinkedIn and take advantage of its social power.

Why integrate with LinkedIn?

I almost hear you saying: “LinkedIn seems interesting but what can I do with it?”, here are just a few things you can do with it:

  • Use LinkedIn contact data to enrich your companies directory information
  • Integrate with your applicant tracking system: perhaps run a specific query periodically to fill a pipeline of possible candidates for a given position or as you open a new position define certain keywords and use them to run a search on LinkedIn and gather potential applicants automatically (see below for a sample query).
  • Automatically sync your LinkedIn contacts with another online directory such as Gmail
  • Push out content (blog posts, yammer updates) to LinkedIn

LinkedIn

The LinkedIn Cloud Connector has been developed to help you interact with LinkedIn public API. You can, for example, retrieve your contacts, get your network updates, send invites, search for people and much more.

Using the LinkedIn Cloud Connector is pretty straightforward. First you need to declare this namespace in your Mule configuration file:

Note that the schema URI does not exist. Instead, the xsd file is packaged inside the LinkedIn Cloud Connector JAR file under /META-INF/mule-linkedin.xsd and is referenced by the /META-INF/spring.schemas file which maps the namespace URI with the physical location of the schema file.

Then set up the connector with your API key and secret which you can obtain by registering your application in the LinkedIn’s developer site:

Let’s say you want to search for people working at MuleSoft and get their published Twitter accounts as well as their last names, sounds difficult? Not really:

What now? Wouldn’t you want to send them an invite to join your network? This is how you do it:

Finally you most likely want to update your LinkedIn status and also share it in Twitter telling others how much you enjoyed this post:

These are just a few operations of the 20+ the LinkedIn Cloud Connector offers you. For a complete list check the online documentation.

Authenticating with OAuth

Explaining what OAuth is is beyond the scope of this post but you can check this entry if you need more background on this topic. This Cloud Connector is intended to be used in Web based application since OAuth requires user interaction through a Web browser. The OAuth authentication flow was developed using the new Mule DevKit which facilitates writing OAuth-enabled Cloud Connectors. The first time an operation that requires authentication is invoked the browser will be redirected to a LinkedIn site where the user can authorize your application.

I will leave the explanation of how to develop a OAuth-enabled Cloud Connector using the new Mule DevKit for a later post due to space restrictions but in the mean time you can check the online documentation here.

Want to try out LinkedIn Cloud Connector?

Make sure you have this repository configured in your pom.xml:

and then add the LinkedIn Cloud Connector Maven dependency:

   <dependency>
     <groupId>org.mule.modules</groupId>
     <artifactId>mule-module-linkedin</artifactId>
     <version>1.0</version>
   </dependency>

If you have any questions I’ll be happy to get back to you. Please leave your comments or questios here or in the forums.

 
follow: @federecio @mulejockey


We'd love to hear your opinion on this post


3 Responses to “Connector of the Week: Using the LinkedIn API”

  1. Hello Federico,

    I tried your example to change the status of a linkedin account, but I always get the exception:

    Root Exception stack trace:
    org.mule.api.oauth.NotAuthorizedException: This connector has not yet been authorized, please authorize by calling “authorize”.

    My flow looks like this:

    Agree(0)Disagree(0)Comment
  2. Hello Federico,

    I am facing same issue of what Tom is facing. And adding to that

    ERROR 2012-06-04 10:27:11,150 [main] org.mule.tooling.server.application.ApplicationDeployer: null
    java.lang.ClassNotFoundException: org.mule.api.oauth.OAuth1Adapter
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:303)

    Please share if you can suggest us any point.

    Regards
    Guru

    Agree(0)Disagree(0)Comment
  3. Am getting the same error

    this is my code

    this is my error

    + Started app ‘linkedin’ +
    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    ERROR 2014-03-15 16:45:10,281 [[linkedin].connector.http.mule.default.receiver.03] org.mule.exception.DefaultMessagingExceptionStrategy:
    ********************************************************************************
    Message : Failed to invoke authorize. Message payload is of type: String
    Code : MULE_ERROR–2
    ——————————————————————————–
    Exception stack is:
    1. Service provider responded in error: 403 (Forbidden) (oauth.signpost.exception.OAuthCommunicationException)
    oauth.signpost.AbstractOAuthProvider:245 (null)
    2. Communication with the service provider failed: Service provider responded in error: 403 (Forbidden) (oauth.signpost.exception.OAuthCommunicationException)
    oauth.signpost.AbstractOAuthProvider:218 (null)
    3. oauth.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Service provider responded in error: 403 (Forbidden) (org.mule.api.oauth.UnableToAcquireRequestTokenException)
    org.mule.module.linkedin.adapters.LinkedInConnectorOAuth1Adapter:242 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/oauth/UnableToAcquireRequestTokenException.html)
    4. Failed to invoke authorize. Message payload is of type: String (org.mule.api.MessagingException)
    org.mule.module.linkedin.processors.AuthorizeMessageProcessor:181 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html)
    ——————————————————————————–
    Root Exception stack trace:
    oauth.signpost.exception.OAuthCommunicationException: Service provider responded in error: 403 (Forbidden)
    at oauth.signpost.AbstractOAuthProvider.handleUnexpectedResponse(AbstractOAuthProvider.java:245)
    at oauth.signpost.AbstractOAuthProvider.retrieveToken(AbstractOAuthProvider.java:193)
    at oauth.signpost.AbstractOAuthProvider.retrieveRequestToken(AbstractOAuthProvider.java:74)
    + 3 more (set debug level logging or ‘-Dmule.verbose.exceptions=true’ for everything)
    ********************************************************************************

    Agree(0)Disagree(0)Comment