Hey there, fellow developer! Ready to dive into the world of LinkedIn API integration? Let's get cracking with this guide using the awesome zoonman/linkedin-api-php-client
package. We'll keep things concise and to the point, just the way we like it.
Before we jump in, make sure you've got:
First things first, let's get your LinkedIn app set up:
Time to let Composer work its magic:
composer require zoonman/linkedin-api-php-client
Easy peasy, right?
Now for the fun part - OAuth 2.0 flow:
use LinkedIn\Client; $client = new Client( 'your_client_id', 'your_client_secret' ); $loginUrl = $client->getLoginUrl(); // Redirect user to LinkedIn for authentication header('Location: ' . $loginUrl); exit;
Once the user comes back, grab that access token:
$accessToken = $client->getAccessToken($_GET['code']);
With your access token in hand, the LinkedIn world is your oyster:
// Get profile info $profile = $client->get('me'); // Post an update $share = $client->post( 'ugcPosts', [ 'author' => 'urn:li:person:' . $profile['id'], 'lifecycleState' => 'PUBLISHED', 'specificContent' => [ 'com.linkedin.ugc.ShareContent' => [ 'shareCommentary' => [ 'text' => 'Check out this cool API integration!' ], 'shareMediaCategory' => 'NONE' ] ], 'visibility' => [ 'com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC' ] ] );
LinkedIn sends back JSON, so let's parse it:
$profileData = json_decode($profile, true); echo "Hello, " . $profileData['localizedFirstName'];
Don't forget to catch those pesky exceptions:
try { // Your API calls here } catch (\LinkedIn\Exception $e) { echo "Oops! " . $e->getMessage(); }
Want to level up? Try refreshing access tokens:
$newAccessToken = $client->refreshAccessToken($refreshToken);
And there you have it! You're now armed and ready to integrate LinkedIn into your PHP application. Remember, the LinkedIn API is your playground - experiment, create, and most importantly, have fun!
Need more info? Check out the official LinkedIn API docs and the zoonman/linkedin-api-php-client GitHub repo.
Now go forth and code something awesome! 🚀