PHP code example of phillipsdata / linkedin

1. Go to this page and download the library: Download phillipsdata/linkedin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phillipsdata / linkedin example snippets


$linkedin = new LinkedIn(
    'LINKEDIN_API_KEY',
    'LINKEDIN_API_SECRET',
    'LINKEDIN_CALLBACK_URL'
);


$permissions_url = $linkedin->getPermissionUrl(
    array(
        'r_basicprofile',
        'r_liteprofile',
        'w_share',
        'w_member_social'
    )
);


$tokenResponse = $linkedin->getAccessToken($_GET['code']);

if ($tokenResponse->status() == 200) {
  // Record $tokenResponse->response() in some way
} else {
  echo $tokenResponse->errors();
}


$data = [
    'author' => 'urn:li:person:123456',
    'lifecycleState' => 'PUBLISHED',
    'specificContent' => [
        'com.linkedin.ugc.ShareContent' => [
            'shareCommentary' => [
                'text' => "Leverage LinkedIn's APIs to maximize engagement"
            ],
            'shareMediaCategory' => 'NONE'
        ]
    ],
    'visibility' => ['com.linkedin.ugc.MemberNetworkVisibility' => 'PUBLIC']
];

$shareResponse = $linkedin->post('v2/ugcPosts', $data);

$shareResponse->headers(); // An array of header fields and their values
$shareResponse->raw(); // Exactly what was returned by LinkedIn, including headers
$shareResponse->response(); // An object containing the data returned by LinkedIn
$shareResponse->errors(); // Any errors given in the response
$shareResponse->status(); // The status code returned by the request

$shareResponse = $linkedin->share('Leverage LinkedIn's APIs to maximize engagement');

$shareResponse = $linkedin->share(
    'Leverage LinkedIn's APIs to maximize engagement',
    [
        'urn' => 'urn:li:digitalmediaAsset:C5422AQEbc381YmIuvg',
        'type' => 'IMAGE',
        'title' => 'LinkedIn API',
        'description' => 'Shows how great the LinkedIn API is.'
    ],
    'CONNECTIONS'
);