LinkedIn API V2 - How to upload photo as binary file

房东的猫 提交于 2019-12-24 16:51:28

问题


I'm having trouble with the second step of uploading a post with a photo seen 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);

This is what my request looks like. I tried without using the type= line but that didn't change anything. I'm getting an empty response and a status code of 400.

I'm using the upload URL from step 1 so I know that should be correct.

What about my request looks wrong? I'm trying to follow the cURL example they gave in the documentation, but perhaps the format of my file isn't correct?

I have also tried making the file parameter of post fields just be the full file path but that gave a response of false.

Another thing for me to mention is the file path has spaces in it.


回答1:


You should include the sytem path of the file eg:user/myname/image.jpg. Content type should be application/binary



来源:https://stackoverflow.com/questions/54789489/linkedin-api-v2-how-to-upload-photo-as-binary-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!