Authenticating with OAuth 2.0 For LinkedIn Api Access using PHP
![]() |
LinkedIn Oauth 2.0 PHP Access |
Follow these steps to enable your application to make
authenticated API calls to LinkedIn using OAuth 2.0:
Step 1: Configuring your LinkedIn application.
Create application in linkedin Developers Panel Link.
After Clicking on Create App. Fill the form information.
Once you save your configuration, your application will be assigned a unique "Client ID" and "Client Secret" value.
Step2: Using the below PHP code to get the LinkedIn access Token to access there apis
After Clicking on Create App. Fill the form information.
Once you save your configuration, your application will be assigned a unique "Client ID" and "Client Secret" value.
Step2: Using the below PHP code to get the LinkedIn access Token to access there apis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(-1); | |
echo " testing"; | |
/** | |
* | |
*The below is the url to get the Authorization code using our LinkedIn App Details | |
*/ | |
$url="https://www.linkedin.com/". | |
'oauth/v2/authorization?response_type=code&client_id=81vfvatntv3k0&' | |
. 'redirect_uri=http://localhost/servers/link.php&state=DCEeFWf45A53sdfKef424'; | |
$code=$_GET['code']; | |
if(isset($code)){ | |
$myUrl = "https://www.linkedin.com/oauth/v2/accessToken"; | |
$myData = array( | |
'grant_type' => 'authorization_code', | |
'code' => $code, | |
'redirect_uri' => '********',//Redirect Url | |
'client_id'=>'CLINETId',//Linkedin App Client Id | |
'client_secret'=>'******'//Linkedin App Secret Key | |
); | |
$myHeaders = array( | |
'Content-type: application/x-www-form-urlencoded' | |
); | |
$handle = curl_init(); | |
curl_setopt($handle, CURLOPT_URL, $myUrl); | |
curl_setopt($handle, CURLOPT_HTTPHEADER, $myHeaders); | |
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($handle, CURLOPT_SSL_VERIFYHOST, false); | |
curl_setopt($handle, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($handle, CURLOPT_POST, true); | |
//curl_setopt($handle, CURLOPT_POSTFIELDS, $myData); | |
curl_setopt($handle, CURLOPT_POSTFIELDS, http_build_query($myData)); | |
$response = curl_exec($handle); | |
$code = curl_getinfo($handle, CURLINFO_HTTP_CODE); | |
print "return code = $code <br/>"; | |
print "response = <br/> $response <br/><br/>"; | |
$myRespArr = json_decode($response, true); | |
print "<pre>"; | |
print_r($myRespArr['access_token']); | |
print "</pre>"; | |
exit; | |
} | |
?> | |
<html> | |
<head> | |
<title>Linkedin Api </title> | |
</head> | |
<body> | |
<a href="<?php echo $url?>">Click Link | |
</a> | |
</body> | |
</html> | |