PHP LinkedIn Authentication AccessToken – LinkedIn OAuth 2.0
Today, We want to share with you PHP LinkedIn Authentication AccessToken – LinkedIn OAuth 2.0.
In this post we will show you How to get a LinkedIn Access Token, hear for php – unable to retrieve access token linkedin api we will give you demo and example for implement.
In this post, we will learn about How to get an extended LinkedIn User Access Token with an example.
Get Access Tokens – LinkedIn Login – LinkedIn for Developers
To get Access Token for LinkedIn We need to Simple First Devloper accont as well as create a LinkedIn web-application and get the get Authentication Keys Like as a USER or Client ID and Simple Key of Client Secret. Also We will need to use Social Media LinkedIn API with some Package Like OAuth PHP library to get the user Uses to Access Token. This LINKEDIN Access Token will expire in About 60 days.
Create a LinkedIn Application:
First of all simple LinkedIn To create a application Below the following steps:
Step 1 : Go to first here LinkedIn Devloper Account
Step : 2 And then Next step to simple click on Create new Application button.
Step : 3 After that All the Fill required fields in Your True Information linkedin form and Form submit. And then your LinkedIn web-application has been created successfully display Message.
We can get the USER client ID and simple generate client secretKey under LinkedIn Authentication Keys.
Check here Authentication Permissions Like as a w_share in “Default Application Permissions” in LinkedIn and simple update. The w_share linkedin permission will All the futures grant We the LinkedIn permission to share Your Data content or images, media on LinkedIn using the PHP API.
LinkedIn : Get Access Token Source Code
Here simple way to get linkedin access token We need to use In this source code using get LinkedIn API and PHP OAuth. Therefor First of all the download Library OAuth using PHP. And then Main root to create a file getaccesstoken.php and copy and following Source code:
getaccesstoken.php
//include libs require_once("OAuth.php"); $data = array( 'consumer_key' => '{YOUR_CLIENTID_PUT_HERE}', 'consumer_secret' => '{YOUR_SECRET_KEY}', 'callback_url' => 'callback.php' ); $livemethod = new OAuthSignatureMethod_HMAC_SHA1(); $live_consumer = new OAuthConsumer($data['consumer_key'], $data['consumer_secret']); $token = NULL; $params = array('scope' => 'w_share'); $live_req = OAuthRequest::from_consumer_and_token($live_consumer, $token, 'GET', "https://api.linkedin.com/uas/oauth/requestToken", $params); $live_req->set_parameter("oauth_callback", $data['callback_url']); $live_req->sign_request($livemethod, $live_consumer, $token); $live_req = http($live_req->to_url()); function http($url, $curl_post_data = null) { $live_curlch = curl_init(); if(defined("CURL_CA_BUNDLE_PATH")) curl_setopt($live_curlch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH); curl_setopt($live_curlch, CURLOPT_URL, $url); curl_setopt($live_curlch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($live_curlch, CURLOPT_TIMEOUT, 30); curl_setopt($live_curlch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($live_curlch, CURLOPT_SSL_VERIFYPEER, 0); if(isset($curl_post_data)) { curl_setopt($live_curlch, CURLOPT_POST, 1); curl_setopt($live_curlch, CURLOPT_POSTFIELDS, $curl_post_data); } $results = curl_exec($live_curlch); curl_close($live_curlch); //function return return $results; } parse_str($live_req, $token); $_SESSION['oauth_request_token'] = $token['oauth_token']; $_SESSION['oauth_request_token_secret'] = $token['oauth_token_secret']; if(is_array($token)){ $token = $token['oauth_token']; } $request_link = "https://api.linkedin.com/uas/oauth/authorize?oauth_token=" . $token; header('Location: '. $request_link); exit;
We will be Call back means redirected to a Main User LinkedIn Wall page for allow the web application to simple share the Data content on your steps to behalf.
After click on Allow Access We will be redirected to the callback page.
Now Make the PHP callback.php page to simple this source code to get the linkedin access token.
callback.php
require_once("OAuth.php"); $data = array( 'consumer_key' => '{YOUR_CLIENTID_PUT_HERE}', 'consumer_secret' => '{YOUR_SECRET_KEY}', 'callback_url' => 'callback.php' ); if(isset($_REQUEST['oauth_verifier'])){ $data['oauth_token'] = $_SESSION['oauth_request_token']; $data['oauth_token_secret'] = $_SESSION['oauth_request_token_secret']; $method = new OAuthSignatureMethod_HMAC_SHA1(); $live_consumer = new OAuthConsumer($data['consumer_key'], $data['consumer_secret']); $token = new OAuthConsumer($data['oauth_token'],$data['oauth_token_secret']); $params = array(); $live_req = OAuthRequest::from_consumer_and_token($live_consumer, $token, 'GET', "https://api.linkedin.com/uas/oauth/accessToken", $params); $live_req->set_parameter("oauth_verifier", $_REQUEST['oauth_verifier']); $live_req->sign_request($method, $live_consumer, $token); $live_req = http($live_req->to_url()); function http($url, $curl_post_data = null) { $live_curlch = curl_init(); if(defined("CURL_CA_BUNDLE_PATH")) curl_setopt($live_curlch, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH); //PHP curl_setting curl_setopt($live_curlch, CURLOPT_URL, $url); curl_setopt($live_curlch, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($live_curlch, CURLOPT_TIMEOUT, 30); curl_setopt($live_curlch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($live_curlch, CURLOPT_SSL_VERIFYPEER, 0); if(isset($curl_post_data)) { curl_setopt($live_curlch, CURLOPT_POST, 1); curl_setopt($live_curlch, CURLOPT_POSTFIELDS, $curl_post_data); } $results = curl_exec($live_curlch); curl_close($live_curlch); //function return return $results; } //parsing parse_str($live_req, $token); $get_tokens = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret'], 1); $access_token = serialize($get_tokens); }
We can use linkedin access token to share the content on LinkedIn. Hope linkedin tutorial will help We.
We hope you get an idea about LinkedIn API with OAuth 2.0
We would like to have feedback on my Information blog .
Your valuable any feedback, Good question, Inspirational Quotes, or Motivational comments about this article are always welcome.
If you liked this post, Please don’t forget to share this as Well as Like FaceBook Page.
We hope This Post can help you…….Good Luck!.