Click here to Skip to main content
Click here to Skip to main content

Linkedin API for contacts retrieve

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

Introduction

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.

Background

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:

http://developer.linkedin.com/documents/sign-linkedin

http://developer.linkedin.com/

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 http://platform.linkedin.com/in.js

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

API LINKEDIN 

<script type="text/javascript" src="http://platform.linkedin.com/in.js">     
    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
</script>

<script type="text/javascript">
function onLinkedInLoad(){ 
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 < result.jobs.values.length; 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;\">" + result.jobs.values[i].company.name + "</div>" + result.jobs.values[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=\"http://static02.linkedin.com/scds/common/u/img/icon/icon_no_photo_80x80.png\"></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")]
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:LinkedinScriptManager runat="server"></{0}:LinkedinScriptManager>")]
    public class LinkedinScriptManager : WebControl
    {
        [Bindable(false)]
        [DefaultValue("")]
        [Browsable(false)]
        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)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string APIKEY
        {
            get
            {
                String s = (String)ViewState["APIKEY"];
                return ((s == null) ? String.Empty : s);
            }

            set
            {
                ViewState["APIKEY"] = value;
            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.APIKEY != string.Empty)
            {
                base.OnInit(e);
                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.   

History

Updated the article based on comments received.

License

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

About the Author

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

Comments and Discussions

 
Question[My vote of 2] Full source code sample Pinmemberkiquenet.com27-Dec-13 0:20 
Questionhow to download this source Pinmemberravi.r.potdar@gmail.com15-Sep-13 9:36 
QuestionSource Code PinmemberMember 411626125-Dec-12 5:00 
Questionwhere project PinmemberSerdar Şengül22-Nov-12 21:37 
AnswerRe: where project PinmemberVincenzo Malvone27-Nov-12 8:14 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 17 Oct 2012
Article Copyright 2012 by Vincenzo Malvone
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid