LinkedIn API Integration with Website
LinkedIn API is used for authorization via LinkedIn account, auto-posting company content, and displaying profile on your website. Relevant for B2B products and corporate portals.
OAuth2 Authorization
Route::get('/auth/linkedin/redirect', function () {
return redirect('https://www.linkedin.com/oauth/v2/authorization?' . http_build_query([
'response_type' => 'code',
'client_id' => config('services.linkedin.client_id'),
'redirect_uri' => route('auth.linkedin.callback'),
'scope' => 'openid profile email w_member_social',
'state' => Str::random(16),
]));
});
Route::get('/auth/linkedin/callback', function (Request $request) {
$tokenResp = Http::post('https://www.linkedin.com/oauth/v2/accessToken', [
'grant_type' => 'authorization_code',
'code' => $request->code,
'redirect_uri' => route('auth.linkedin.callback'),
'client_id' => config('services.linkedin.client_id'),
'client_secret' => config('services.linkedin.client_secret'),
])->json();
$accessToken = $tokenResp['access_token'];
// Get user profile
$profile = Http::withToken($accessToken)
->get('https://api.linkedin.com/v2/userinfo')
->json();
// $profile contains: sub (ID), name, email, picture
return redirect('/dashboard');
});
Publishing Company Post
LinkedIn API v2 requires application registration and Marketing Developer Platform approval (for posting):
import requests
def create_company_post(access_token: str, org_id: str, text: str) -> str:
headers = {
'Authorization': f'Bearer {access_token}',
'X-Restli-Protocol-Version': '2.0.0',
}
payload = {
'author': f'urn:li:organization:{org_id}',
'lifecycleState': 'PUBLISHED',
'specificContent': {
'com.linkedin.ugc.ShareContent': {
'shareCommentary': {'text': text},
'shareMediaCategory': 'NONE',
}
},
'visibility': {'com.linkedin.ugc.MemberNetworkVisibility': 'PUBLIC'},
}
resp = requests.post('https://api.linkedin.com/v2/ugcPosts', headers=headers, json=payload)
return resp.json()['id']
Limitations
LinkedIn API strictly regulates access. For corporate posting, you need application verification through the LinkedIn Partner Program. Approval timeline is 4–6 weeks.
Implementation time (OAuth authorization): 2–3 business days. Corporate posting: depends on LinkedIn approval.







