Home > linkedin > How to use LinkedIn Javascript API

How to use LinkedIn Javascript API

Before integrating with Linkedin javascript API we need to register our application with Linkedin.

To do this go to  https://www.linkedin.com/secure/developer, in the Javascript domains add your application URL, localhost is accepted

Below code will describes how to add linkedin sign in button to your application.

Sample JSP file:


<!-- 1. Include the LinkedIn JavaScript API and define a onLoad callback function -->

<script type="text/javascript" src="http://platform.linkedin.com/in.js">

api_key: your_api_key

scope: r_network,r_emailaddress,r_fullprofile,r_basicprofile,r_contactinfo

</script>

</head>

<body>

<!-- need to be logged in to use Search; if not, offer a login button -->

<script type="IN/Login"></script>

</body>

That’s it, linkedin sign in button will appear in your page, if you click on it based on the scope it will ask your permissions.

For searching people from your application , we have to use Linkedin People Search API

To use linkedin search API, i have developed small program. It will ask for first name and last name, based on the given data it will search in linked in and prints the result in UI.


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>LinkedIn JavaScript API Hello World</title>

<script src="http://code.jquery.com/jquery-1.8.2.js"></script>

<!-- 1. Include the LinkedIn JavaScript API and define a onLoad callback function -->

<script type="text/javascript" src="http://platform.linkedin.com/in.js">

api_key: your_api_key

scope: r_network,r_emailaddress,r_fullprofile,r_basicprofile,r_contactinfo

</script>

<script type="text/javascript">

function searchClick() {

alert($("#firstNameId").val()+":"+$("#lastNameId").val());

if (!IN.ENV.auth.oauth_token) {

alert("You must login w/ LinkedIn to use the Search functionality!");

return;

}

IN.API.PeopleSearch()

.fields("id", "firstName", "lastName","emailAddress","headline","industry","pictureUrl","positions",

"summary","numConnections")

.params({

"first-name": $("#firstNameId").val(),

"last-name": $("#lastNameId").val(),

"count":25

})

.result(function(result, metadata) {

setSearchResults(result.people.values);

});

}

function setSearchResults(values) {

var table = $("#resulttable");

table.append('<tr><th>First Name</th><th>Last Name</th><th>Head Line</th><th>Industry</th><th>Picture</th><th>No Of Connections</th><th>Summary</th><th>Positions</th></tr>');

for (i in values) {

try{

var person = values[i];

var positionsStr = "<ul>";

for(i in person.positions.values){

positionsStr+="<li>"+person.positions.values[i].company.name+"</li>";

}

console.log(positionsStr);

table.append('<tr><td>'+

person.firstName+'</td><td>'+

person.lastName+'</td><td>'+

person.headline+'</td><td>'+

person.industry+'</td><td><img src="'+

person.pictureUrl+'"/></td><td>'+

person.numConnections+'</td><td>'+

person.summary+'</td><td>'+

positionsStr+'</ul></td></tr>')

}catch(err){alert(err);}

}

}

</script>

</head>

<body>

<!-- need to be logged in to use Search; if not, offer a login button -->

<div align="right">

<script type="IN/Login"></script>

</div>

<center>

<p>Basic test of the People Search API via Connect.</p>

First Name: <input type="text" name="firstName" id="firstNameId"/><br/>

Last Name: <input type="text" name="lastName" id="lastNameId"/><br/>

<input type="button" name="searchLinkedIn" value="Search LinkedIn!" onclick="searchClick();"/>

</center>

<table id="resulttable">

</table>

</body>

</html>

Thats it, for further info regarding Linkedin API http://api.linkedin.com/

About these ads
Categories: linkedin
  1. August 12, 2013 at 5:48 pm

    I have given the domain name as http://localhost ..but its displaying the login button

  2. August 13, 2013 at 10:26 am

    My project is in E:drive ..should i give the path name of it..or project name is enough?

    • rameshcharykotha
      August 13, 2013 at 9:32 pm

      When you run the application, You can see the URL in browser. Please give that.
      Usually it will be your project name.

  3. August 14, 2013 at 10:21 am

    thanks fa ur reply..i jus need a guidance from u..???will u pls help me..??? i have given the my domain name as.. http://domainname.in..but am not getting the login button..should i upload the js file separately in server .?? can u guess wat will be the error??

  4. August 14, 2013 at 11:05 am

    http://www.iexemplar.com/website/Dev/linkedin.html …this s my domain name..pls help me to get the login button

  5. August 14, 2013 at 12:17 pm

    Thanks a lot..my code is working well..

  6. August 16, 2014 at 3:33 am

    Nice post. I learn something new and challenging on blogs I stumbleupon on a daily
    basis. It will always be helpful to read content from other
    authors and use something from other web sites.

  7. August 24, 2014 at 8:13 am

    I like the helpful information you supply for your articles.
    I’ll bookmark your weblog and test again here frequently.
    I’m rather certain I will be informed many new stuff right right here!
    Good luck for the following!

  8. August 25, 2014 at 7:41 am

    This article gives clear idea designed for the new users of blogging, that actually how to do blogging and site-building.

  9. August 26, 2014 at 7:14 am

    Thanks for finally writing about >How to use LinkedIn Javascript API
    | java2practice <Loved it!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: