Integration of LinkedIn API

posted in: Social Networking | 0

Integration of LinkedIn API

The purpose of this article is how to integrate LinkedIn API in our applications. I covered some of the topics like showing the LinkedIn network people belongs to a company or industry and showing your LinkedIn first degree/second degree connection friends in our application and sending message to your LinkedIn friends.

LinkedIn API uses OAuth as its authentication method. OAuth is a standard for negotiating developer authorization and granting access on behalf of specific members to perform API requests. One of OAuth’s benefits is the availability of many third party and open source libraries, allowing developers to authenticate with LinkedIn quickly and in a similar manner to how they authenticate with services such as Twitter, Google, Yahoo, and Netflix.
OAuth Overview

The below is a high-level architectural diagram of OAuth, and provides the specific settings for using it with the LinkedIn API.

linkd_in

 

 

 

 

The OAuth Flow

The developer (or the “consumer”) requests an API (or consumer) key from LinkedIn (or the “provider”)

A. When your application needs to authenticate the member (or the “user”), your application makes a call to LinkedIn to ask for a request token

B. LinkedIn replies with a request token. Request tokens are used to ask for user approval to the API.

C. Your application redirects the member to LinkedIn to sign-in and authorize your application to make API calls on their behalf. Developer provides LinkedIn with a URL where they should send them afterward (or the “callback”)

 

D. If the member agrees, LinkedIn returns them to the location specified in the callback

E. Your application then makes another OAuth call to LinkedIn to retrieve an access token for the member

F. LinkedIn returns an access token, which has two parts: the oauth_token and oauth_token_secret.

G. After retrieving the access token, you can make API calls, signing them with the consumer key and access token

For implementing in your application your must have the Api Key and Secret Key for your application. So go to https://www.linkedin.com/secure/developer and click Add New Application to get them.

People Search API

The People Search API returns information about people. It lets you implement most of what shows up when you do a search for “People” in the top right box on LinkedIn.com.

API Call method:

http://api.linkedin.com/v1/people-search? keywords=[space delimited keywords]& first-name=[first name]& last-name=[last name]& company-name=[company name]& current-company=[true|false]& title=[title]& current-title=[true|false]& school-name=[school name]& current-school=[true|false]& country-code=[country code]& postal-code=[postal code]& distance=[miles]& start=[number]& count=[1-25]&  facet=[facet code, values]& facets=[facet codes]&  sort=[connections|recommenders|distance|relevance]

 

Use the People Search API to find people using keywords, company, name, or other criteria. It returns a list of matching member profiles. Each entry can contain much of the information available on the person’s member profile page.

Use Field Selectors to explicitly enumerate the exact fields you want. This ensures the call returns in the least amount of time.

As a starting point, the People API default looked like this: /people-search:(people:(id,first-name,last-name,headline,location:(name,country:(code),postal-code),industry,num-recommenders,connections,summary,specialties,interests,honors,positions,educations,member-url-resources,api-standard-profile-request,site-standard-profile-request,public-profile-url))?query

The API can also return facets. Facets provide you with data about the collection of people, such as where they work, are located, or what schools they attended. You can then use this data to make a new API call that further refines your original request. This is similar to clicking the buttons on the left-hand side of the LinkedIn Search results page

Facets

Facets provide you with data similar to what appears on left-hand side of the LinkedIn Search results page.

Use facets to discover for a member:

– Who in their network works at a specific company, or group of companies.

– How the people their network cluster together. What locations or industries are the most popular?

– Where their connections graduated from school.

 

To find the First degree connections in a company use this API call:

http://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url,public-profile-url,positions:(title)),num-results)?company-name=Collabor&facets=network&facet=network,F&start=1&count=200

For second degree connections in a company,

http://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url,public-profile-url,positions:(title)),num-results)?company-name=Asda&facets=network&facet=network,S&start=1&count=200

For Industry type (eg. IT Software),

http://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name,headline,picture-url,public-profile-url,positions:(title)),num-results)??facets=industry,network&facet=industry,96&facet=network,F&start=1&count=200

You can get more information from http://developer.linkedin.com/docs/DOC-1012

For sending a message to the user use this function,

function sendMessage($xml){

$status_url = “http://api.linkedin.com/v1/people/~/mailbox”;

$request = OAuthRequest::from_consumer_and_token$this->consumer, $this->access_token, “POST”, $status_url);

$request->sign_request($this->signature_method, $this->consumer, $this->access_token);

$auth_header = $request->to_header(“https://api.linkedin.com”);

$response = $this->httpRequest($status_url, $auth_header, “POST”, $xml);

return $response;

}

 

Xml will be as follows for sending a message.

$xml ='<?xml version=”1.0″ encoding=”UTF-8″?>

<mailbox-item>

<recipients>

‘.12345(LinkedIn person_id).’

</recipients>

<subject>’.$custom_subject.'</subject>

<body>’.htmlentities($custom_message).'</body>

</mailbox-item>’;

$content = $linkedin->sendMessage($xml);

Previous Post
Next Post

Leave a Reply