I am the owner and admin of a LinkedIn company page: https://www.linkedin.com/company/{id}/
.
I want to connect to LinkedIn and get return a JSON-feed with latest 10 posts on my company wall to display on my website so I touch on the service https://api.linkedin.com/v1/companies/{id}/updates?format=json
.
The JSON is outputted in linkedin.php
. This file is then included in my web page, say index.php
.
I have registrered an app at https://developer.linkedin.com. I have entered my Client ID and Client Secret in PHP-LinkedIn-SDK available here https://github.com/ashwinks/PHP-LinkedIn-SDK.
I followed the developer documentation I need to authenticate first. When I run linkedin.php
I am redirected to sign into my LinkedIn profile. I have to finish this step in order to touch the service above.
With the current solution my users will have to login into LinkedIn when they access my website.
How can I access a list of my company's LinkedIn posts without prompting my users to sign in?
Thanks.
1. Generate your access token
Follow the documentation https://github.com/ashwinks/PHP-LinkedIn-SDK to create a login link.
2. Save your access token
Once you get it, it will be available for 60 days. Save it into your database.
3. Fetch your company posts
You can use the same access token to fetch company contents
$li = new LinkedIn(...);
$li->setAccessToken(YOUR_ACCESS_TOKEN);
$posts = $li->get('/companies/YOUR_COMPANY_ID/updates/');
4. Manage response
Cache or display the response after parsing it.
Hope that helps,
Use https://packagist.org/packages/linkedinapi/linkedin
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere'
)
);
//Get the login URL - this accepts an array of SCOPES
$url = $li->getLoginUrl(
array(
LinkedIn::SCOPE_BASIC_PROFILE,
LinkedIn::SCOPE_EMAIL_ADDRESS,
LinkedIn::SCOPE_NETWORK
)
);
/*LinkedIn will redirect to 'callback_url' with an access token as the 'code' parameter. You might want to store the token in your session so the user doesn't have to log in again*/
$token = $li->getAccessToken($_REQUEST['code']);
$token_expires = $li->getAccessTokenExpiration();
//Make a request to the API
$info = $li->get('/people/~:(first-name,last-name,positions)');
$li = new LinkedIn(
array(
'api_key' => 'yourapikey',
'api_secret' => 'yourapisecret',
'callback_url' => 'https://yourdomain.com/redirecthere',
'curl_options' => array(
CURLOPT_PROXY => '127.0.0.1:80',
),
)
)