PHP code example of fabatek / laravel-linkedin

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

    

fabatek / laravel-linkedin example snippets


$app->register(\Artesaos\LinkedIn\LinkedinServiceProvider::class);
class_alias(\Artesaos\LinkedIn\Facades\LinkedIn::class,'LinkedIn');

$app->configure('linkedin');

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

LinkedIn::foo();

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

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

LinkedIn::get('v1/people/~:(firstName,num-connections,picture-url)');

LinkedIn::setAccessToken('access_token_from_db');

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

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

$options = array(
'format' => 'xml',
'body' => '<share>
 <comment>Im testing Happyr LinkedIn client! https://github.com/Happyr/LinkedIn-API-client</comment>
 <visibility>
   <code>anyone</code>
 </visibility>
</share>');

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

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

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

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

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

// Set format for just one request
LinkedIn::get('v1/people/~:(firstName,lastName)', array('response_data_type'=>'psr7'));


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

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

'LinkedIn'  => \Artesaos\LinkedIn\Facades\LinkedIn::class,

php artisan vendor:publish --provider="Artesaos\LinkedIn\LinkedinServiceProvider"