File tree 4 files changed +54
-0
lines changed
4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,16 @@ Change default API root
234
234
$client->setApiRoot('https://api.linkedin.com/v2/');
235
235
```
236
236
237
+ Try to upload image to LinkedIn. See [ Rich Media Shares] ( ) https://developer.linkedin.com/docs/guide/v2/shares/rich-media-shares#upload )
238
+ (returns "Not enough permissions to access media resource" for me).
239
+ I assume you have to be LinkedIn partner or something like that.
240
+
241
+ ``` php
242
+ $filename = '/path/to/image.jpg';
243
+ $client->setApiRoot('https://api.linkedin.com/');
244
+ $mp = $client->upload($filename);
245
+ ```
246
+
237
247
## Contributing
238
248
239
249
Please, open PR with your changes linked to an GitHub issue.
Original file line number Diff line number Diff line change 105
105
);
106
106
pp ($ companyShare );
107
107
108
+ /*
109
+ // Returns {"serviceErrorCode":100,"message":"Not enough permissions to access media resource","status":403}
110
+ // You have to be whitelisted or so by LinkedIn
111
+ $filename = './demo.jpg';
112
+ $client->setApiRoot('https://api.linkedin.com/');
113
+ $mp = $client->upload($filename);
114
+ */
108
115
} catch (\LinkedIn \Exception $ exception ) {
109
116
// in case of failure, provide with details
110
117
pp ($ exception );
Original file line number Diff line number Diff line change @@ -279,6 +279,7 @@ public function getAccessToken($code = '')
279
279
'headers ' => [
280
280
'Content-Type ' => 'application/json ' ,
281
281
'x-li-format ' => 'json ' ,
282
+ 'Connection ' => 'Keep-Alive '
282
283
],
283
284
]);
284
285
try {
@@ -532,6 +533,42 @@ public function post($endpoint, array $params = [])
532
533
return $ this ->api ($ endpoint , $ params , Method::POST );
533
534
}
534
535
536
+ /**
537
+ * @param $path
538
+ * @return array
539
+ * @throws Exception
540
+ */
541
+ public function upload ($ path )
542
+ {
543
+ $ headers = $ this ->getApiHeaders ();
544
+ unset($ headers ['Content-Type ' ]);
545
+ //$headers = [];
546
+ if ($ this ->isUsingTokenParam ()) {
547
+ //
548
+ } else {
549
+ $ headers ['Authorization ' ] = 'Bearer ' . $ this ->accessToken ->getToken ();
550
+ }
551
+ $ guzzle = new GuzzleClient ([
552
+ 'base_uri ' => $ this ->getApiRoot ()
553
+ ]);
554
+ $ options = [
555
+ 'multipart ' => [
556
+ [
557
+ 'name ' => basename ($ path ),
558
+ 'filename ' => basename ($ path ),
559
+ 'contents ' => fopen ($ path , 'r ' )
560
+ ]
561
+ ],
562
+ 'headers ' => $ headers ,
563
+ ];
564
+ try {
565
+ $ response = $ guzzle ->request (Method::POST , 'media/upload ' , $ options );
566
+ } catch (RequestException $ requestException ) {
567
+ throw Exception::fromRequestException ($ requestException );
568
+ }
569
+ return self ::responseToArray ($ response );
570
+ }
571
+
535
572
/**
536
573
* @param array $params
537
574
* @param string $method
You can’t perform that action at this time.
0 commit comments