Create User Profile from LinkedIn Data
What were trying to achieve here is to save the user time creating a user profile from LinkedIn profile by typing in everything from scratch and simply click “Create Profile” and it grabs the data from LinkedIn to create the users profile dynamically. This way of creating the LinkedIn data and storing it in a seperate table instead of directly into the user profile table is that you could do an import from any Social Network most likely Facebook or Twitter and then specify individual fields for each peice of profile information. Ie – the user could use thier Facebook profile pic, LinkedIn employment history and twitter status giving them great flexibility and speed for thier profile.
What you need:
- SQL Database with a LinkedIn table and User Profile table
- The LinkedIn API PHP class includes
- A LinkedIn API secret oAuth key
- Some PHP (below)
- Some JavaScript/jQuery (below)
How it works:
The user clicks “Import from LinkedIn” on profile page.

The user allows access to thier LinkedIn profile.

This is an example of the data which gets returned.

The profile is auto generated and displayed using AJAX.

How to do it:
1. Setup your SQL database tables
[code lanf="js"]
--
-- Table structure for table `prof_linkedin_data`
--
CREATE TABLE IF NOT EXISTS `prof_linkedin_data` (
`profLinkedinId` int(10) NOT NULL AUTO_INCREMENT,
`uid` int(10) NOT NULL,
`first-name` varchar(255) NOT NULL,
`last-name` varchar(255) NOT NULL,
`picture-url` varchar(255) NOT NULL,
`public-profile-url` varchar(255) NOT NULL,
`headline` varchar(255) NOT NULL,
`current-status` varchar(255) NOT NULL,
`summary` text NOT NULL,
`industry` varchar(255) NOT NULL,
`specialties` varchar(255) NOT NULL,
`location` varchar(100) NOT NULL,
PRIMARY KEY (`profLinkedinId`),
UNIQUE KEY `uid` (`uid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
--
-- Table structure for table `prof_data`
--
CREATE TABLE IF NOT EXISTS `prof_data` (
`profId` bigint(10) NOT NULL AUTO_INCREMENT,
`uid` bigint(10) NOT NULL,
`profFirstName` varchar(50) NOT NULL,
`profLastName` varchar(50) NOT NULL,
`profProfilePic` varchar(255) NOT NULL,
`profCurrentPosition` varchar(100) NOT NULL,
`profIndustry` varchar(255) DEFAULT NULL,
`profOrganisation` varchar(255) DEFAULT NULL,
`profLocation` varchar(100) NOT NULL,
`profSummary` text NOT NULL,
`profSpecialties` varchar(255) NOT NULL,
`default` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`profId`),
KEY `profIndustryId` (`profIndustry`),
KEY `profOrganisationId` (`profOrganisation`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
[/cc]
2. Include and Setup your LinkedIn API Classes
To load in your classes you could use a function like this (the DIR constant is a reference to your server root directory).
private function _loadLinkedInIncs()
{
require_once(DIR."social/classes/linkedin.class.php");
require_once(DIR."social/classes/oauth.php");
require_once(DIR."social/classes/config.php");
}
This is an example of the LinkedIn config.php file.
define('CALLBACK_URL', DOMAIN.'/storeLinkedInData.php');
define('BASE_API_URL', 'https://api.linkedin.com');
define('REQUEST_PATH', '/uas/oauth/requestToken');
define('AUTH_PATH', '/uas/oauth/authorize');
define('ACC_PATH', '/uas/oauth/accessToken');
define('CUSTOMER_KEY', '03e3kh3b8w6'); //i've changed so update to your keys
define('CUSTOMER_SECRET', 'yLGbunMaSWMkApf');
3. Create your PHP
This is how you go about asking the user for access to thier LinkedIn data(references to $this refer to the PHP object which holds these functions). I'll have to assume you know all about Object Oriented programming in PHP, I'll try to cover some basics in another post.
public function importLinkedIn()
{
$this->_loadLinkedInIncs(); // load linkedIn includes
$this->linkedin = new linkedin(); //create linkedIn obj
$this->linkedin->init(); // start (not needed for public profile calls)
}
4. Create your JavaScript/jQuery
Here is the code for the button handler event for "Import from LinkedIn". When the button is clicked the LinkedIn API window appears in a popup and a setInterval function monitors for when the popup window closes. When it does close it knows to refresh with the profile information.
[code lanf="js"]
$('#import-linkedin-btn').live('click', function(e)
{
e.preventDefault();
var containerElem = $('#container'),
loadingElem = $('#loading');
//show loading image
container.html(loadingElem.clone().show());
//monitor the closing of a popup window
var win = window.open("http://domain.com/importLinkedIn.php",'','height=400,width=700');
var winTimer = window.setInterval(function()
{
if (win.closed !== false)
{
// !== is required for compatibility with Opera
window.clearInterval(winTimer);
//load the users profile
setTimeout(function()
{
/*----------------------------------------------
load in profile data from database using AJAX
----------------------------------------------*/
}, 1000);
}
}, 200);
});
[/cc]
I'm working on a demo which I'll post soon.
Sorry there is no demo and the code is slightly vague, feel free to ask any questions and I'll get a demo online for you soon.