LinkedIn API V2 - 如何将照片上传为二进制文件

问题描述 投票:1回答:1

我在上传帖子的第二步遇到问题here

$post_fields = array(
    'file' => '@' . $_FILES['file-attachment']['tmp_name']
        . ';filename=' . $_FILES['file-attachment']['name']
        . ';type='     . $_FILES['file-attachment']['type']
);

$upload_response = process_curl(array(
    CURLOPT_URL => $upload_url,
    CURLOPT_HEADER => false,
    CURLOPT_TIMEOUT => 10,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_POSTFIELDS => $post_fields,
    CURLOPT_HTTPHEADER => array('Authorization: Bearer '.$token, 'x-li-format: json','Content-Type: multipart/form-data'),
), true);

这就是我的要求。我尝试没有使用type=线,但没有改变任何东西。我收到空响应,状态代码为400。

我正在使用第1步中的上传网址,所以我知道这应该是正确的。

我的要求怎么看错了?我正在尝试按照他们在文档中提供的cURL示例,但可能我的文件格式不正确?

我也尝试使post字段的file参数只是完整的文件路径但是响应为false。

我要提到的另一件事是文件路径中有空格。

php linkedin linkedin-api php-curl
1个回答
1
投票

您应该包括文件的系统路径,例如:user / myname / image.jpg。内容类型应为application / binary

© www.soinside.com 2019 - 2024. All rights reserved.