dthswrp84966 2018-11-29 06:40
浏览 55

自动化cron发送邮件到linkedin公司

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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog
    • ¥15 Excel发现不可读取的内容