Use the LinkedIn PHP Class to integrate LinkedIn into your website. This Tutorial shows you how step by step. In this first part I'll explain how to set up a connection with the LinkedIn API and show you how you can fetch a basic profile. In the next parts I'll explain how you can post network and status updates.

OAuth and the LinkedIn PHP Class

The LinkedIn PHP Class uses the OAuth extension of PHP. This extension can be installed via PECL. More information about the installation can be found here: LinkedIn Developer Network of Installation of Pecl extensions.

Before you start you need to download the LinkedIn PHP Class, unzip the file and upload linkedin_v4.php to your server. Include the file where you want to use it require_once('/pad/naar/linkedin_v4.php').

Step 1: LinkedIn Object

You start by creating a new linkedin object. The linkedin object needs your apiKey and secretKey to connect with LinkedIn. If you don't have an apiKey yet, you can get it here. The callback is optional.

$apiKey		= '--apikey--';
$secretKey	= '--secretkey--';
$callback	= 'http://voorbeeld.nl/linkedin/test';
$linkedin	= new Linkedin($apiKey,$secretKey,$callback);

Authorization procedure

The code above doesn't do anything yet. When you make your first request the class will authorize via OAuth. In simpel words the authorization via OAuth works as follows:

  1. A request token is retreived from LinkedIn and the user will be redirected to an authorization page at LinkedIn where he will be asked to enter his username (email) and password. LinkedIn then knows the user grants you permission to retreive his information via the API.
  2. LinkedIn sends the user back to the given callback url. The class now retreives an acces token. You'll need the access token to do requests.
  3. With each request a signature string will be generated based on the apiKey, secretKey and the access token. Without this signature string the request can't be done.

GET, PUT and POST

There are three different methods to retreive and send information to LinkedIn. GET, PUT and POST. GET will get you information (e.g. your profile). PUT is used to update something that is already there (e.g. your status) and POST is used to create something new (e.g. a network update, comment or message). These methods are simplified by the LinkedIn PHP Class.

Step 2: Basic profile

Lets start by retreiving your basic profile.

// Basic profile information without extra options
$profile = $linkedin->getData();

$linkedin->getData() retreives the basic profile of a user. LinkedIn returns XML, but the class transforms this in a workable PHP Array. $profile now contains:

Array
(
    [first-name] => Jeroen
    [last-name] => Sentel
    [headline] => Internet ( Business ) Developer
    [site-standard-profile-request] => Array
        (
            [url] => http://www.linkedin.com/profile?viewProfile=&key=12458484&authToken=zdHN&authType=name
        )

)

Connections and Network Updates

In Part 2 I'll further explain the options that can be used with getData() and fetching network updates and connections. Untill then you could try out the class yourself. The comments in the file will explain a lot.

Also see the LinkedIn API documentatie.

Join my LI API Developers Group on LinkedIn.

Comments or suggestions can be posted below.