Happyr / LinkedIn-API-client

A library to connect with LinkedIn API. Perfect if you are looking for an API client or SDK for LinkedIn
MIT License
198 stars 97 forks source link

"Rich media" share issue - multipart/form-data #159

Closed scottybo closed 6 years ago

scottybo commented 6 years ago
Q A
Bug? unsure
New Feature? unsure
Are you using composer? yes
Version 1

Actual Behavior

I need to upload Rich Media following the LinkedIn docs: https://developer.linkedin.com/docs/guide/v2/shares/rich-media-shares#upload

Expected Behavior

A URN response, e.g.

{
  "location": "urn:li:richMediaSummary:PNG-IMG-54f022ae8b3f4d479e925b4df68e19"
}

Actual response

array (
  'serviceErrorCode' => 0,
  'message' => 'The request is not a multipart request',
  'status' => 400,
)  

Steps to Reproduce

I'm struggling to send Multipart/form data to the LinkedIn API via Happyr. I've attempted all sorts of ways to get this to work, and here's the the last attempt before creating this issue:

$file = file_get_contents($this->post['media_url']);

$multipart = [
    [
        'name'     => 'image',
        'contents' => $file                    
    ]
];

$boundary = sha1(uniqid('', true));

$photo_options = [
    'headers' => [
        'Content-Type'=>'multipart/form-data; boundary=--'.$boundary.'--'
    ],
    'body' => new \GuzzleHttp\Psr7\MultipartStream($multipart,$boundary)
];

$photos_response = LinkedIn::post('media/upload', $photo_options);

Possible Solutions

Add support for multipart forms (or guide on how to do this properly)