Saturday 3 August 2019

Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net

In this article I will explain how to login with LinkedIn Account in ASP.Net Website and get LinkedIn User Profile details like ID, Name, Profile Picture, Email Address, etc. using the free ASPSnippets.LinkedInAPI.
This article also explains how create a LinkedIn Application and get the LinkedIn API Key and Secret Key on LinkedIn Developers Site.
 
Get LinkedIn API Key and Secret Key on LinkedIn Developers Site
In order to create an application you need to visit the Linked Developer site using the following URL.
There you need to click Add New Application button.
Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net
 
After that you need to fill the following form, inside which the most important section is the Default Scope where you need to choose what User details you want to fetch through your application.
Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net
 
Once the form is submitted, you will get the LinkedIn API Key and Secret Key as shown below.
Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net
 
 
Downloading and referencing Free ASPSnippets LinkedIn API
You can download the free ASPSnippets LinkedIn API from following URL
And either add it using Add Reference or copy it inside the BIN folder of your website.
 
 
HTML Markup
In the below HTML Markup, I have an ASP.Net Button which triggers the LinkedIn Authorization process. Once the user profile details are fetched, it will be displayed using the Label and Image controls.
<asp:Button Text="Login with LinkedIn" runat="server" OnClick="Authorize" />
<asp:Panel ID="pnlDetails" runat="server" Visible="false">
    <hr />
    <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 />
    Industry:
    <asp:Label ID="lblIndustry" runat="server" /><br />
    Headline:
    <asp:Label ID="lblHeadline" runat="server" />
</asp:Panel>
 
 
Namespaces
You will need to import the following namespaces.
C#
using System.Data;
using ASPSnippets.LinkedInAPI;
 
VB.Net
Imports System.Data
Imports ASPSnippets.LinkedInAPI
 
 
 
LinkedIn Authorization and fetching the LinkedIn User Profile details
The very first thing you need to do is set the LinkedIn API Key and Secret Key to its respective properties.
Inside the Button click event handler, the Authorize method is called which will redirect user to the LinkedIn Website where he will login and also grant permissions to the application to fetch his profile details.
Once the user has authorized the LinkedIn Profile details are fetched using the Fetch method as DataSet object and are displayed on page using Image and Label controls.
C#
protected void Page_Load(object sender, EventArgs e)
{
    LinkedInConnect.APIKey = "<Your LinkedIn API Key>";
    LinkedInConnect.APISecret = "<Your LinkedIn API Secret>";
    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 = ds.Tables["person"].Rows[0]["email-address"].ToString();
        lblHeadline.Text = ds.Tables["person"].Rows[0]["headline"].ToString();
        lblIndustry.Text = ds.Tables["person"].Rows[0]["industry"].ToString();
        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 Authorize(object sender, EventArgs e)
{
    LinkedInConnect.Authorize();
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgsHandles Me.Load
    LinkedInConnect.APIKey = "<Your LinkedIn API Key>"
    LinkedInConnect.APISecret = "<Your LinkedIn API Secret>"
    LinkedInConnect.RedirectUrl = Request.Url.AbsoluteUri.Split("?")(0)
    If LinkedInConnect.IsAuthorized Then
        pnlDetails.Visible = True
        Dim ds As DataSet = 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 = ds.Tables("person").Rows(0)("email-address").ToString()
        lblHeadline.Text = ds.Tables("person").Rows(0)("headline").ToString()
        lblIndustry.Text = ds.Tables("person").Rows(0)("industry").ToString()
        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()
    End If
End Sub
 
Protected Sub Authorize(sender As Object, e As EventArgs)
    LinkedInConnect.Authorize()
End Sub
 
Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net

Login with LinkedIn Account and fetch User Profile details like ID, Name, Picture and Email in ASP.Net

4 comments:

  1. LassoIn.com is a very new site that was launched recently. I registered on it as an experiment. So far no issues, it does offers some of the basic features that have been making the job of posting simpler. Comment, follow, subscribe are a few features that the site offers. The site makes it easy for me to post content from my website to LinkedIn followers.

    ReplyDelete
  2. The shift to digital media is being driven by marketing agencies, business owners and consumers alike. The ever-increasing demand to show quantifiable results makes going digital a dream for the digital marketing agency. Best Digital Marketing Blog India

    ReplyDelete
  3. The blog has been written in a manner that there isn't anything that has been left revealed, and furthermore, I have perused different web journals that are posted here and they are altogether worth a read.
    youtube bellen

    ReplyDelete
  4. The blog has been written in a manner that there isn't anything that has been left revealed, and furthermore, I have perused different web journals that are posted here and they are altogether worth a read.
    visit site

    ReplyDelete