Working with LinkedIn in XPages – People Search

Here is another example for accessing LinkedIn’s API’s in XPages. This example contains code for performing a people search within your network.

I will include the example later in the next release of LinkedIn controls.

<?xml version=”1.0″ encoding=”UTF-8″?>
<xp:view xmlns:xp=”http://www.ibm.com/xsp/core&#8221;
xmlns:xc=”http://www.ibm.com/xsp/custom&#8221; createForm=”false”>
<head>
<title>LinkedIn JavaScript API Sample Application</title>
<xc:ccLinkedInAPIKey key=”//your  domain key here”></xc:ccLinkedInAPIKey>
<script type=”IN/Login”></script>
<xp:scriptBlock id=”scriptBlock3″>
<xp:this.value><![CDATA[function PeopleSearch() {
// Call the PeopleSearch API with the viewer’s keywords
// Ask for 4 fields to be returned: first name, last name, distance, and Profile URL
// Limit results to 10 and sort by distance
// On success, call displayPeopleSearch(); On failure, do nothing.
var keywords = dojo.byId(“#{id:searchBox}”).value;
IN.API.PeopleSearch()
.fields(‘firstName’, ‘lastName’, ‘distance’, ‘siteStandardProfileRequest’)
.params({‘keywords': keywords, ‘count': 10, ‘sort': ‘distance’})
.result(displayPeopleSearch)
.error(function error(e) { /* do nothing */ }
);
}]]></xp:this.value>
</xp:scriptBlock>
<xp:scriptBlock id=”scriptBlock4″>
<xp:this.value><![CDATA[function displayPeopleSearch(peopleSearch) {
var div = document.getElementById(“peopleSearchResults”);
div.innerHTML = “<ul>”;
// Loop through the people returned
var members = peopleSearch.people.values;
for (var member in members) {

// Look through result to make name and url.
var nameText = members[member].firstName + ” ” + members[member].lastName;
var url = members[member].siteStandardProfileRequest.url;

// Turn the number into English
var distance = members[member].distance;
var distanceText = ”;
switch (distance) {
case 0: // The viewer
distanceText = “you!”
break;
case 1: // Within three degrees
case 2: // Falling through
case 3: // Keep falling!
distanceText = “a connection ” + distance + ” degrees away.”;
break;
case 100: // Share a group, but nothing else
distanceText = “a fellow group member.”;
break;
case -1: // Out of netowrk
default: // Hope we never get this!
distanceText = “far, far, away.”;
}
div.innerHTML += “<li><a href=\”” + url + “\”>” + nameText +
“</a> is ” + distanceText + “</li>”
}
div.innerHTML += “</ul>”;
}]]></xp:this.value>
</xp:scriptBlock>

</head>

<h1>Find People on LinkedIn</h1>
<xp:inputText id=”searchBox” defaultValue=”xpages”></xp:inputText>
<xp:button value=”Search” id=”button1″>
<xp:eventHandler event=”onclick” submit=”false”>
<xp:this.script><![CDATA[
PeopleSearch();]]></xp:this.script>
</xp:eventHandler>
</xp:button>
<div id=”peopleSearchForm”></div>
<div id=”peopleSearchResults”></div>
</xp:view>

Custom control ccLinkedInAPIKey you can find in the LinkedIn controls project.

Without any styling your result could look something similar like this:

About these ads

Born in Holland, current country of residence is Sweden. IBM Notes Consultant since 1997. Main focus is Xpages development. Other interests: computers, motorcycles, music (bass guitar) & cooking.

Tagged with: , , , , ,
Posted in XPages

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

Introduction
I am Patrick Kwinten. I am a IBM Notes Domino Product Specialist since 1996. With this blog I am trying to give my contribution to the community.

The posts in this blog project my personal opinions, not the company I work for.
.

C U in Orlando

ibmconnected

CV
OpenNTF
Follow my projects on OpenNTF. Below are some examples:

Categories
RSS Feed
Follow

Get every new post delivered to your Inbox.

Join 235 other followers

%d bloggers like this: