Click here to Skip to main content
12,753,061 members (38,198 online)
Click here to Skip to main content
Add your own
alternative version


9 bookmarked
Posted 11 Oct 2012

Linkedin API for contacts retrieve

, 17 Oct 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
API Linkedin for Contacts retrive


In this article I have tried to create a toolkit through a small set of controls that allow the synchronization of information via Linkedin such as Contacts.

The toolkit is made ​​by Statto C # ajax on the model and predict the creation of a ScriptManager js that all amounts required to instantiate the API calls to the world Linkedin.

The dialogue with the Linkedin system requires a exchange their credentials through a redirect on the login system of the web platform.


The code described in this article allows you to create easily one schmea of API calls to retrieve all the information related to your contacts in linkedin.

The ability to perform a query on the platform linkedin requires that the application you are using has at its disposal a APIKEY issued by the web linkeind

To understand how it is possible to obtain a APIKEY refer to the links provided below:

The operations of the request to the API linkedin require an exchange of credentials through the support provided by token generated dynamically and which allows to obtain authorization to send operations web credentials to the access area of Linkedin.

The transfer of information from the web client to tunnel linkedin is guaranteed by TLS or SSL enabled on browsere allows for secure sending of our credentials.

All the necessary script is contained within

Using the code

Briefly present the code needed to create the ScriptManager that will allow the import of the information entered in the files are embedded inseritinella library:

This script can be inserted within any file


<script type="text/javascript" src="">     
    api_key: your key
    onLoad: onLinkedInLoad
    scope: r_fullprofile r_network r_contactinfo rw_groups w_messages rw_nus
    authorize: true
    credentials_cookie: true
    credentials_cookie_crc: true
IN.Event.on(IN, "auth", onLinkedInAuth);}
function onLinkedInAuth() {
  if (document.getElementById("compania")) {
     IN.API.Raw("/people/~/suggestions/job-suggestions").method("GET").result(function (result) {
     document.getElementById("compania").innerHTML = "";
     for (i = 0; i <; i++) {
           document.getElementById("compania").innerHTML += "<table><tr><td><img src=\"../img/icon_no_    company.gif\"></td><td><div style=\"font-size:14px;color:#006699;padding-bottom:5px;font-weight:bold;\">" +[i] + "</div>" +[i].descriptionSnippet + "</td></tr></table><br/>" + "<br/><div style=\"border-bottom:1px dotted #a0a0a0\"/>";
.error(function error(e) { alert("Error" + JSON.stringify(e)) });

if (document.getElementById("connectionsdata")) {
   IN.API.Connections("me").fields("id", "firstName", "lastName", "pictureUrl", "publicProfileUrl").result(function (result, metadata) {
setConnections(result.values, metadata);

function setConnections(connections) {
  var connHTML = "<ul>";
  for (id in connections) {
  connHTML = connHTML + "<li><a href=\"" + connections[id].publicProfileURL + "\">";

   /* picture url not always there, must be defensive */
  if (connections[id].hasOwnProperty('pictureUrl')) {
       connHTML = connHTML + "<img align=\"baseline\" src=\"" + connections[id].pictureUrl + "\"></a>";
} else {
     connHTML = connHTML + "<img align=\"baseline\" src=\"\"></a>";


   connHTML = connHTML + "&nbsp;<a href=\"" + connections[id].publicProfileUrl + "\">";
   connHTML = connHTML + connections[id].firstName + " " + connections[id].lastName + "</a></li>";


  connHTML = connHTML + "</ul>";
  document.getElementById("connectionsdata").innerHTML = "";
  document.getElementById("connectionsdata").innerHTML = connHTML;

Briefly present the code needed to create the ScriptManager that will allow the import of the information entered in the files are embedded inseritinella library:

Personally I prefer to use a RESX file indexed by a voice Resources.Resource.ScriptManager.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;

using System.Web.UI.WebControls;  
[System.Drawing.ToolboxBitmap(typeof(LinkedinContacts), "img.My_linkedin_icon.bmp")]
    [ToolboxData("<{0}:LinkedinScriptManager runat="server"></{0}:LinkedinScriptManager>")]
    public class LinkedinScriptManager : WebControl
        public string pathJsBase;

<span class="Apple-tab-span" style="white-space: pre; ">    </span>// APIKEY is release by LINKEDIN 
        [B// APIKEY is release by LINKEDIN indable(true)]indable(true)]
        public string APIKEY
                String s = (String)ViewState["APIKEY"];
                return ((s == null) ? String.Empty : s);

                ViewState["APIKEY"] = value;

        protected override void OnInit(EventArgs e)
            if (this.APIKEY != string.Empty)
                Page.Init += delegate(object sender, EventArgs e_Init)
                    pathJsBase = Resources.Resource.ScriptManager;
                    Literal linkJs = new Literal();
                    linkJs.Text = pathJsBase.Replace("{#}", this.APIKEY);

                    Control head = null;
                    head = findControl(Page.Controls, typeof(System.Web.UI.HtmlControls.HtmlHead));

                    if (head != null)
                        if (linkJs.Text != string.Empty) head.Controls.Add(linkJs);

        public System.Web.UI.Control findControl(System.Web.UI.ControlCollection inCollectionControls, Type inTypeControlType)
            System.Web.UI.Control outControlGeneric;
            System.Web.UI.Control curControl;

            for (int i = 0; i < inCollectionControls.Count; i++)
                curControl = inCollectionControls[i];
                if (curControl.GetType() == inTypeControlType)
                    outControlGeneric = curControl;
                    return outControlGeneric;

                if (curControl.Controls.Count > 0)
                    outControlGeneric = findControl(curControl.Controls, inTypeControlType);

                    if (outControlGeneric != null)
                        return outControlGeneric;
            return null;

        protected override void Render(HtmlTextWriter output) { }

Points of Interest

This article allows you to interact with protocol OAuth 2.0 and to understand some patterns. The protocol allows to understand the use of the Token system used in different steps. It also allows you to have fun with the mechanisms of retrograde asynchronously by using JSON and AJAX.   


Updated the article based on comments received.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vincenzo Malvone
Italy Italy
Vincenzo Malvone
ICT Engineer System Analyst - Solution Developer .NET

You may also be interested in...

Comments and Discussions

Questionlinkdin api source file download Pin
Member 111666558-Dec-14 2:51
memberMember 111666558-Dec-14 2:51 
Question[My vote of 2] Full source code sample Pin
kiquenet.com27-Dec-13 1:20
memberkiquenet.com27-Dec-13 1:20 
Questionhow to download this source Pin
ravi.r.potdar@gmail.com15-Sep-13 10:36
memberravi.r.potdar@gmail.com15-Sep-13 10:36 
QuestionSource Code Pin
Member 411626125-Dec-12 6:00
memberMember 411626125-Dec-12 6:00 
Questionwhere project Pin
Serdar Şengül22-Nov-12 22:37
memberSerdar Şengül22-Nov-12 22:37 
AnswerRe: where project Pin
Vincenzo Malvone27-Nov-12 9:14
memberVincenzo Malvone27-Nov-12 9:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 17 Oct 2012
Article Copyright 2012 by Vincenzo Malvone
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid