Integrate LinkedIn with ASP.Net

Steps to Integrate LinkedIn with ASP.Net is given below.

1)Create an Application in LinkedIn Developer site using the following URL.

https://www.linkedin.com/secure/developer

Log In with LinkedIn login ID and CreateApp to get the API key and API Secret key for the application.

Generated API and Secret key for LinkedIn

Generated API key

 

 

 

 

 

 

2)Add generated keys in the code and add a reference to the DLL of LinkedIn API.

Download DLL for LinkedIn API here

3)A Login button will be displayed when you run the application.

LinkedIn LogIn Button

 

 

 

 

4)Once the user authorized the application and grants access to his profile and account details, a call is made to Fetch method of ASPSnippets LinkedIn API to get Name,LinkedInId,Location and Email Address as DataSet. This is done through ASPSnippets LinkedIn API and LinkedIn OAUTH API.

Aspx Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <h2>
                Linked API Integration
            </h2>
            <asp:Button ID="Button_LinkedIn" Text="Login with LinkedIn" runat="server" OnClick="Button_LinkedIn_Click"/>
            <asp:Panel ID="pnlDetails" runat="server" Visible="false">
                <br />
                <asp:Image ID="imgPicture" runat="server" /><br />
                Name:
    <asp:Label ID="lblName" runat="server" /><br />
                LinkedInId:
    <asp:Label ID="lblLinkedInId" runat="server" /><br />
                Location:
    <asp:Label ID="lblLocation" runat="server" /><br />
                EmailAddress:
    <asp:Label ID="lblEmailAddress" runat="server" /><br />
            </asp:Panel>
        </div>
    </form>
</body>
</html>

 

C# Code

protected void Page_Load(object sender, EventArgs e)
       {
           string APIKey = ConfigurationManager.AppSettings["APIKey"];
           string APISecret = ConfigurationManager.AppSettings["APISecret"];
           LinkedInConnect.APIKey = APIKey;
           LinkedInConnect.APISecret = APISecret;
           LinkedInConnect.RedirectUrl = Request.Url.AbsoluteUri.Split('?')[0];
           if (LinkedInConnect.IsAuthorized)
           {
               pnlDetails.Visible = true;
               DataSet ds = LinkedInConnect.Fetch();
               imgPicture.ImageUrl = ds.Tables["person"].Rows[0]["picture-url"].ToString();
               lblName.Text = ds.Tables["person"].Rows[0]["first-name"].ToString();
               lblName.Text += " " + ds.Tables["person"].Rows[0]["last-name"].ToString();
               lblEmailAddress.Text = "xxx@gmail.com";
               lblLinkedInId.Text = ds.Tables["person"].Rows[0]["id"].ToString();
               lblLocation.Text = ds.Tables["location"].Rows[0]["name"].ToString();
               imgPicture.ImageUrl = ds.Tables["person"].Rows[0]["picture-url"].ToString();
           }
       }

       protected void Button_LinkedIn_Click(object sender, EventArgs e)
       {
           LinkedInConnect.Authorize();
       }

 

Output

 

Demo Code

Download