Skip to main content

Get User details from LinkedIn Log In account

How to get Username, email, profile image of LinkedIn logged in user.
To implement this one first we need to create simple website & integrate LinkedIn Log in button in this website based on previous post.
Once we integrate LinkedIn authentication now we need to write the code like as shown below to get logged in user details from LinkedIn

function onLinkedInAuth()
{
IN.API.Profile("me")
.fields("firstName", "lastName", "industry", "location:(name)", "picture-url", "headline", "summary", "num-connections", "public-profile-url", "distance", "positions", "email-address", "educations", "date-of-birth")
.result(displayProfiles)
.error(displayProfilesErrors);

}

This function is used to get basic details (firstname, lastname, location, profile image, emailid, friends list, any information we shared publically) of logged in user from LinkedIn.

If you need access to more information, such as the user's email address, etc. you must requestpermissions for this information. For that we need to add permission to scope attribute of the Login Button and our LinkedIn api function will be like this

<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: YOUR_API_KEY
authorize: true
onLoad: onLinkedInLoad
scope: r_basicprofile r_emailaddress r_fullprofile
</script>

By using above method we can get name, email, profile image for that we added some of parameters to get access for our scope attribute of login button. If you want more information then you need to get permission for other objects for that check this link scope permission reference.

To get user details from LinkedIn account we need to write the code like as shown below

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Linkedin Authentication Login in Asp.net Website</title>
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: r5qes40ga0me
authorize: true
onLoad: onLinkedInLoad
scope: r_basicprofile r_emailaddress r_fullprofile
</script>
<script type="text/javascript">
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
function onLinkedInAuth() {
IN.API.Profile("me")
.fields("firstName", "lastName", "industry", "location:(name)", "picture-url", "headline", "summary", "num-connections", "public-profile-url", "distance", "positions", "email-address", "educations", "date-of-birth")
.result(displayProfiles)
.error(displayProfilesErrors);
}

function displayProfiles(profiles) {
member = profiles.values[0];
alert(JSON.stringify(member));

document.getElementById("lblName").innerHTML = member.firstName + " " + member.lastName + "<br/> Location is " + member.location.name ;
document.getElementById("imgProfile").src = member.pictureUrl;
document.getElementById("lblEmail").innerHTML = member.emailAddress;
document.getElementById("lblProfile").innerHTML = member.publicProfileUrl;
}
function displayProfilesErrors(error) {
profilesDiv = document.getElementById("profiles");
profilesDiv.innerHTML = error.message;
console.log(error);
}
</script>

</head>
<body>
<script type="in/Login" >
</script>
<br />
<b>Get Linkedin LoggedIn User Details</b>
<table>
<tr>
<td>Name:</td>
<td><label id="lblName" /></td>
</tr>
<tr>
<td>Email:</td>
<td><label id="lblEmail" /></td>
</tr>
<tr>
<td>Profile Url:</td>
<td><label id="lblProfile" /></td>
</tr><tr>
<td>Profile Image:</td>
<td> <img id="imgProfile" /></td>
</tr>
</table>
<div id="profiles">
</div>
</body>
</html>

Now run your application to see the result.

Popular posts from this blog

Asp.Net Web API

What is ASP.NET Web API? ASP.NET Web API is a framework provided by the Microsoft with which we can easily build HTTP services that can reach a broad of clients, including browsers, mobile, IoT devices, etc. ASP.NET Web API provides an ideal platform for building RESTful applications on the .NET Framework.   Difference between ASP.NET Web API and WCF Web AP I is a Framework to build HTTP Services that can reach a board of clients, including browsers, mobile, IoT Devices, etc. and provided an ideal platform for building RESTful applications. It is limited to HTTP based services. ASP.NET framework ships out with the .NET framework and is Open Source. WCF i.e. Windows Communication Foundation is a framework used for building Service Oriented applications (SOA) and supports multiple transport protocol like HTTP, TCP, MSMQ, etc. It supports multiple protocols like HTTP, TCP, Named Pipes, MSMQ, etc. WCF ships out with the .NET Framework. Both Web API and WCF can be self-hosted or can be...

Creating package in Oracle Database using Toad For Oracle

What are Packages in Oracle Database A package is  a group   of procedures, functions,  variables   and  SQL statements   created as a single unit. It is used to store together related objects. A package has two parts, Package  Specification  and Package Body.