I'm trying to send a new post to a linkedin company (automation via cron).
1- retrieve the post to share from mysql
2- send the post
3- update the database with ID of the post
** I want to do it all 3 in 1 php script **
but with linkedin API it seems we have to get a token and set the token...
first I did with github.com/zoonman/linkedin-api-php-client
$linkedin = new LinkedIn\Client( 'clientID', 'client SECRET' );
$linkedin->setRedirectUrl('callback.php');
$linkedin->setApiHeaders([ 'Content-Type' => 'application/json', 'x-li-format' => 'json', 'X-Restli-Protocol-Version' => '2.0.0', 'x-li-src' => 'msdk' ]);
$loginUrl = $linkedin->getLoginUrl();
echo $loginUrl.'<hr>';
I went to the given URL, linkedin returned me with a token and expiresAt...
after I do
$accessToken = new LinkedIn\AccessToken($linkedin_token, $linkedin_tokenExpire);
$linkedin->setAccessToken($accessToken);
$linkedinShare = $linkedin->post(
'companies/stubfeed/shares',
[
'content' => [
'title' => 'share_title',
'description' => 'share_description',
'submitted-url' => 'share_stubfeed_url',
'submitted-image-url' => 'share_img_url',
],
'visibility' => [
'code' => 'anyone'
]
]
);
var_dump($linkedinShare);
But I get an error
LinkedIn\Exception: Client error: `POST https://api.linkedin.com/v1/companies/stubfeed/shares` resulted in a `401 Unauthorized` response: { "errorCode": 0, "message": "Unable to verify access token", "requestId": "0AGNS6DQ64", "status": 401, "times (truncated...) in /vendor/zoonman/linkedin-api-php-client/src/Exception.php on line 68
What I'm I missing ? Is it possible to automate this process via cron ?
I am able (and it's working) to do it with few others API like twitter, but I'm stuck here...
Thanks