Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Get User’s Profile With Linkedin API Using PHP

In this article, we are going to learn how you can get user’s data with LinkedIn API using PHP. There are a couple of social networks which are popular around the world. Sign in with social media is a trendy module on the Internet.

Nowadays website visitors or users are getting lazier and lazier, the most uncomfortable activity on the Internet is probably “Creating The Account“.

So we need to think about our visitor’s comfort first to make them happier. Because visitors are the most important thing to grow an online business.

get user profile linkedin api using php

LinkedIn API using PHP to get user’s profile data.

We are going to use LinkedIn Profile API to fetch user’s data from their LinkedIn Account. I recommend you to read all mentioned steps below carefully.

Follow these steps to get user’s profile data with LinkedIn API using PHP

Step 1: Creating Application at LinkedIn’s developer console and setting things up.

Step 1.1: Sign in with your LinkedIn account.

Step 1.2: Visit LinkedIn Developer’s page.

Step 1.3: Click on “Create Application” button.

you have to fill all the mandatory fields of the application form.

sign in with linkedin

after filling the form up you will get redirected to the application’s dashboard page (something like bellow one)

linkedin profile api

now copy the Client ID Client Secret credentials and store it, we will use it further.

Step 1.4 – now you have to check (Checkbox) r_emailaddress option in Default Application Permissions section and update your application by clicking on the update button.

Step 1.5 – now you have to add the 

sign in with social media

Step 2: this step contains the actual functionality of API, now we are going to serve a button “Register With LinkedIn” in front of users. When users click on that button they would get redirected to the LinkedIn page, this page asks the user to approve our application, after approval our application can access user’s personal data.

sign in with linkedin

after clicking on “Allow” button users get redirected back to the URL mentioned in Step 1.5:, while this redirection LinkedIn sends some JSON encoded data, this data can be captured easily and can be used as anyway as you want.

Register with LinkedIn Button


{CLIENT_ID}&redirect_uri={REDIRECT_URL}&state=987654321&scope=r_basicprofile">Register With LinkedIn

you have to modify button code as per yours.

  • just replace {CLIENT_ID} with your client_id (see Step 1.3 last line)
  • and {REDIRECT_URL} with redirect URL you provided (see Step 1.5)

Step 3: now its time to get the user’s data, suppose I’ve added the redirect URL as http://domain.com/callback.php (in Step 1.5), so callback.php is the file where all the JSON data would be redirected, you can grab user’s data from this file. In below line, I’m going to show how you can capture the redirected JSON Data.

code for the callback.php file is as follow. This is the file whose location (absolute URL of callback.php file) you have added in Step 1.5


if(isset($_GET['code'])){
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL,"https://www.linkedin.com/oauth/v2/accessToken");
	curl_setopt($ch, CURLOPT_POST, 0);
	curl_setopt($ch, CURLOPT_POSTFIELDS,"grant_type=authorization_code&code=".$_GET['code']."&redirect_uri={REDIRECT_URL}&client_id={CLIENT_ID}&client_secret={CLIENT_SECRET}");
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$server_output = curl_exec ($ch);
	curl_close ($ch);
}

if(isset($_GET['code']) && json_decode($server_output)->access_token != ''){

     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL,"https://api.linkedin.com/v1/people/~?oauth2_access_token=".json_decode($server_output)->access_token."&format=json");
     curl_setopt($ch, CURLOPT_POST, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $server_output2 = curl_exec ($ch);
     curl_close ($ch);

     $user_data = json_decode($server_output2);

     print_r($user_data);

}

so all the user’s data finally get stored in the $user_data variable. You can now store these details in a database as well.

If you find this tutorial helpful please don’t forget to share it with your friends because sharing is a caring!

You may also like

  • Post into Facebook Page using PHP SDK v5
  • Autocomplete Address Search Module Using Google API and PHP
  • Facebook like time ago system in php

The post Get User’s Profile With Linkedin Api Using PHP appeared first on My Programming Tutorials.



This post first appeared on My Programming Tutorials, please read the originial post: here

Share the post

Get User’s Profile With Linkedin API Using PHP

×

Subscribe to My Programming Tutorials

Get updates delivered right to your inbox!

Thank you for your subscription

×