【发布时间】:2016-02-25 04:49:27
【问题描述】:
我正在尝试在我们的项目中实现到 LinkedIn 的共享。它对我来说就像一种魅力,然而,对我所有的同事来说,它都没有。它返回401: Unknown authentication scheme 仅用于共享请求(配置文件请求工作正常)。
我们使用的 LinkedIn 应用程序归我所有。出于测试目的,另一位开发者试图在他的帐户中创建一个应用程序,但问题仍然存在:我是唯一可以分享的人。
我们使用linkedinapi/linkedin 作为后端。代码如下:
protected function openConnection()
{
$credentials = \Config::get('services.linkedin');
try
{
$this->connection = new \LinkedIn\LinkedIn([
'api_key' => $credentials['client_id'],
'api_secret' => $credentials['client_secret'],
'callback_url' => $credentials['redirect'],
]);
$this->connection->setAccessToken(\Auth::user()->linkedin->token['access_token']);
}
catch (\Exception $e)
{
\Log::error('Failed LinkedIn auth, exception is attached', [$e]);
throw new CouldNotPostException('Please, re-link your LinkedIn account, failed to send your post to LinkedIn.');
}
}
protected function send()
{
$object = [
'content' => [
'title' => $this->post->title,
'description' => \Str::limit($this->post->description, 253),
'submitted-url' => $this->post->shortlink,
'submitted_image_url' => \URL::to($this->post->image),
],
'comment' => $this->content,
'visibility' => [
'code' => 'connections-only'
]
];
try
{
$result = $this->connection->post('/people/~/shares?format=json', $object);
$this->posted($result['updateKey']);
}
catch (\Exception $e)
{
\Log::error('Failed LinkedIn posting, exception is attached', [$e]);
throw new CouldNotPostException('Failed to send your post to LinkedIn, our developers have been notified of this error.');
}
}
UPD:原来只能在我的机器上发帖,所以他们机器上的配置有问题。正在寻找它。
【问题讨论】:
标签: php rest linkedin linkedin-api