PHP code example of scottybo / laravel-linkedin-v2

1. Go to this page and download the library: Download scottybo/laravel-linkedin-v2 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/ */

    

scottybo / laravel-linkedin-v2 example snippets


$app->register(\Scottybo\LinkedIn\LinkedinServiceProviderV2::class);
class_alias(\Scottybo\LinkedIn\Facades\LinkedInV2::class,'LinkedInV2');

$app->configure('linkedin-v2');

$linkedIn=new ScottyBo\LinkedIn\LinkedIn('app_id', 'app_secret');
$linkedin->foo();

LinkedInV2::foo();

app('linkedin-v2')->foo();
app()['linkedin-v2']->foo();
App::make('linkedin-v2')->foo(); // ...
 
if (LinkedInV2::isAuthenticated()) {
     //we know that the user is authenticated now. Start query the API
     $user=LinkedIn::get('v2/me');
     echo  "Welcome ".$user['firstName'];
     exit();
}elseif (LinkedInV2::hasError()) {
     echo  "User canceled the login.";
     exit();
}

//if not authenticated
$url = LinkedInV2::getLoginUrl();
echo "<a href='$url'>Login with LinkedIn</a>";
exit();

LinkedIn::get('v2/me');

LinkedInV2::setAccessToken('access_token_from_db');

$options = ['json'=>
     [
        'comment' => 'Im testing Scottybo LinkedIn v2 client with Laravel Framework! https://github.com/scottybo/laravel-linkedin-v2',
        'visibility' => [
               'code' => 'anyone'
        ]
     ]
];

$result = LinkedIn::post('v2/people/~/shares', $options);

$options = array(
'format' => 'xml',
'body' => '<share>
 <comment>Im testing Scottybo LinkedIn v2 client with Laravel Framework! https://github.com/scottybo/laravel-linkedin-v2</comment>
 <visibility>
   <code>anyone</code>
 </visibility>
</share>');

$body = array(
    'comment' => 'Testing the linkedin v2 API!',
    'visibility' => array('code' => 'anyone')
);

LinkedInV2::post('v1/people/~/shares', array('json'=>$body));
LinkedInV2::post('v1/people/~/shares', array('body'=>json_encode($body)));

// By setter
LinkedInV2::setFormat('xml');

// Set format for just one request
LinkedInV2::post('v1/people/~/shares', array('format'=>'xml', 'body'=>$body));

// By setter
LinkedInV2::setResponseDataType('simple_xml');

// Set format for just one request
LinkedInV2::get('v2/me', array('response_data_type'=>'psr7'));


$scope = 'r_fullprofile,r_emailaddress,w_share';
//or 
$scope = array('rw_groups', 'r_contactinfo', 'r_fullprofile', 'w_messages');

$url = LinkedInV2::getLoginUrl(array('scope'=>$scope));
return "<a href='$url'>Login with LinkedIn</a>";

'LinkedInV2'  => \Scottybo\LinkedIn\Facades\LinkedInV2::class,

php artisan vendor:publish --provider="Scottybo\LinkedIn\LinkedinServiceProviderV2"