LinkedIn API and ASP.NET C# adventures

Continuing with integrating LinkedIn with my ASP.NET C# app, I came across a few difficulties.

1. Some browsers block popups differently than others.

Doing development in IE (because it’s better integrated with VS 2012) and doing so on an IIS server on “localhost” doesn’t always give you the same results as when you push to Staging or Production. Case in point, having a popup window for users to log into their LinkedIn account worked well on IE, but failed once it was on staging and with Chrome and FireFox. The solution was to take the popup window outside of the AJAX call and make it a direct “” call from “onclick”.

2. Here’s how I handle whether the user clicked cancel at the LinkedIn authorization page or they actually logged in.

Code Snippet
  1.  <scripttype=”text/javascript”>
  2.      function getURLParameter(name) {
  3.          return decodeURI(
  4.              (RegExp(name + ‘=’ + ‘(.+?)(&|$)’).exec( || [, null])[1]
  5.          );
  6.      }
  7.     $(document).ready(function () {
  8.         var error = getURLParameter(‘error’);
  9.         if (error.indexOf(“null”, 0) != -1) {
  10.             window.opener.linkedInToken = getURLParameter(‘code’);
  11.         }
  12.         window.close();    
  13.     });
  14. </script>

3. When users are logged into their LinkedIn account and you send a user to the linked in auth page, it may automatically detect the user is logged in and send you back immediately to the callback URL you provided. It’s important to handle this case in your logic.

4. oAuth 2 is a million times better than oAuth 1a and storing the user’s access token in your DB makes the process of interacting with LinkedIn much more seamless for your users. If you’re struggling with how to handle JSON returned from LinkedIn, copy the json and paste it into this tool which will auto generate C# classes for your JSON. Then you can use to convert LinkedIn JSON to your custom classes.

Convert JSON to C# classes


Posted in Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *