Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Get LinkedIn Logged in User Details(Name,Email, Url, Profile Image) using JavaScript API

May 10, 2013
Introduction:

Here I will explain how to access or get Username, email, profile image of LinkedIn logged in user using JavaScript.

To implement this one first create app and integrate LinkedIn login in 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 request permissions 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 and check the output that would be like this

Demo



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

28 comments :

Unknown said...

User Couldn't getting sign out from here. What's the solution.

Thanks a lot!

Unknown said...

Sir Please Let Me Know How To Remove Current User Info.

Anonymous said...

nice articles

Anonymous said...

ddddddddddddddddd

Kalai said...

Excellent... Very very useful and simply super.

binil said...

when i am trying to import skills,certifications getting like [object Object],undefined etc .
how to solve this issue

Anonymous said...

plese tell me how to logout after fetching the data

Ano mepani said...

how to create same example for Rest API using redirect_uri,and Exchnage authorization_code and access_token

Unknown said...

hy it's working thanks

Unknown said...

hey it is working fine but i want to fetch data from facebook account who are logged in ,

sakinala said...

thanks its working
but how logout from it
there is no logout button showing there

Unknown said...

thanks alot it it very useful but i want to retrive contacts information like firstname location etc..of contacts how can i do it . please help me

Anonymous said...

how to get contacts list

Unknown said...

yesterday when i run the code it was working fine but today i'm not gettinng linkedin Sign-in Button..plz help me..

Sushma said...

Hi Umarfarooq Galibwale,

This happens when you are logged in your linked in account. Logout from linkedin and you will again see the login button on your site.

vikas said...

good work

i am unable to find the api for geting the connections


Anonymous said...

How I will get the count of likes & shares of my linkedIn post?

Anonymous said...

sd6t7uvgh56hfg

Unknown said...

Hi i have integrated linkedin authentication like you have done.its working fine locally but its not working on server.have you tried on server.i guess in.js is not loading on server.can you please help me??

Unknown said...

Suppose I am using a custom login button, but after the login, login button is not disappearing, can I use .isAuthorized, or some like that any other method , so that on the basis of the same, I can use Updatepanel to display login and logout button.
Thanks

Suma said...

Hi,
Am not getting linked in sign in button..

Unknown said...

Hi,
in my case i need to create a LinkedIn search engine to search candidate contact information .if i will put name of the candidate result should be related information needs to show .please anybody can help me .i googled many days i didn't get .please any one can help
Thanks!
Bageeradha Vajja
bageeradhavajja@gmail.com

Divyesh Kanzariya said...

You save my day. Thank you suresh. :)

Unknown said...

How can I extract or get the LinkedIn recommendations for my website?

Unknown said...

How can I extract or get the LinkedIn recommendations and endorsement for my website?
I am able to get basic information as well as number no connections. But I am unable to get recommendations received and endorsement for my asp.net website. Please anyone can help. Thanks in advance!

Unknown said...

I used Javascript API for LinkedIn web integration in my website. Using this javascript API, I am able to get basic details like Name, industry, summary, headline, number of connections. Apart from these details, I need to know how many members endorsement him/her. And who are all recommanded him/her. These two details i am unable to get. Please anyone help. Thanks in Advance!

Reshma said...

I have tried the same method. I'm able to login but not getting the profile details. The callbacks(success/error) are not getting triggered! Can anyone help me please.

Vikky said...

How can I get contact number along with those details

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.