Clojure and LinkedIn API

This weekend I didn’t know exactly what to learn or play with, and since I have never played before with the LinkedIn API, I thought that it could be fun to use in Clojure, instead of Java or Python. Therefore, we are going to talk about the LinkedIn API and how to get you starting with a simple Clojure web app that gets your profile name.

There are two options for getting data from LinkedIn, REST APIs or JavaScript APIs. In this small web app, we are going to use the REST API since the JavaScript is quite simple and you can get it up and running in 15 min, literally.

The steps involved in the authentication using OAuth 2.X are the following (according to their site):

  1. Register your application.
  2. Get an access token.
  3. Request access token by exchanging the authorization_code for it.
  4. Make the API calls.

It couldn’t be simpler (, right?). I am going to assume that you have already registered your application (if not, follow the link). So, we can strike the Register your Application step.

Second step, this one is just a little bit more complex, but not that much. As we can see from the snippet of code, this is just a simple function that displays a button within a form which triggers a POST request.

If we read from the LinkedIn table below, those are the parameters that you send (do not forget the https instead of http). So far, so good (I hope).


When the user authorises our app, (s)he is redirected to the link that we gave in the redirect_uri query parameter where we find as well a couple of query parameters, in this case, the authorization code and the state:


Third step, we are going to use the authorization code to get the access token which gives us access to the user information through the REST API. In order to get the access token, we need to issue a POST request like the one below:

As we did before, you can take a look at the table and check the meaning of each query parameter.


The response that we get from the server is going to be an object of the form:


Nonetheless, since we are using Ring, we have added automatically :body to the object thus, getting something like:


The function that we displayed before (request-access-token.clj) gets the access_token and passes it to another function that does the query to the LinkedIn API:

As we can see in the login function, if there is an authorization token, we proceed by getting the access_token, and finally make a formal request to LinkedIn. If there is no authorization token, then we just display another view.

So, this is it!!! It’s just that simple. You can find the project up and ready to go on my github repository, and the source code of the handler at the end of this entry.

I hope you can continue developing your web-app from this point on, and get some fun!!!

This entry was published on May 19, 2013 at 1:52 pm. It’s filed under Uncategorized and tagged , , , , . Bookmark the permalink. Follow any comments here with the RSS feed for this post.

3 thoughts on “Clojure and LinkedIn API

  1. I delight in, result in I found just what I was looking for.
    You’ve ended my 4 day long hunt! God Bless you man. Have a nice day. Bye

  2. Araceli on said:

    Enhorabuena por el aporte es muy bueno.
    Llevo un tiempo implementando la API de Linkedin en una aplicación Web, y necesito tu ayuda porque ya no se como avanzar y me estoy volviendo loca 🙂

    En realidad tengo dos problemas :

    1 – Obtengo el Access_token sin problemas pero por lo que he visto en internet tiene una vida util muy corta, de 20 segundos, como puedo hacer para ampliar el tiempo?

    2- Me han pedido saltarse el paso de autentificación y sacar de Base de datos el usuario y clave de linkedin , he conseguido nada mas iniciar esa pantalla que el email salga por defecto según el usuario, pero no consigo poner la clave esto se puede hacer?

    Por cierto estoy trabajando con

    Me seria de gran utilidad tu ayuda.
    Muchas gracias de antemano.

  3. It’s not working anymore. I’m getting clojure.lang.ExceptionInfo
    clj-http: status 401. Any help?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: