From 52df944e9a59d91f8446c5391f16385bc459b85f Mon Sep 17 00:00:00 2001 From: Bogdan Symchych Date: Mon, 7 Jul 2014 20:09:35 +0300 Subject: [PATCH 1/3] Update Client.php For correct work of posting shares, I made some changes. Now it's possible to use GET data and POST data in single request. And now it's posible to send XML POST. POST data sending as 4 parameter in `fetch` method. Worked example from real project: $client = new \Splash\LinkedIn\Client($apiKey, $secretKey); $client->setAccessToken($token); $data = " This is title This is body http://someurl.com/ http://lorempixel.com/400/400/nightlife/ anyone "; $response = $client->fetch('/v1/people/~/shares', array(), 'POST', $data); --- lib/Splash/LinkedIn/Client.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/Splash/LinkedIn/Client.php b/lib/Splash/LinkedIn/Client.php index f4ae67e..3c414d4 100644 --- a/lib/Splash/LinkedIn/Client.php +++ b/lib/Splash/LinkedIn/Client.php @@ -50,13 +50,13 @@ public function __construct($api_key, $api_secret, $curl = null) { * @param string $method * @return array */ - public function fetch($resource, array $payload = array(), $method = 'GET') { + public function fetch($resource, array $payload = array(), $method = 'GET', $postData = null) { $url = $this->domain . $resource; $payload = array('oauth2_access_token' => $this->getAccessToken(), 'format' => 'json') + $payload; - return $this->_request($url, $payload, $method); + return $this->_request($url, $payload, $method, $postData); } /** @@ -117,10 +117,10 @@ public function fetchAccessToken($verification_code, $redirect_uri) { * @return array JSON-decoded response * @throws Exception */ - protected function _request($url, array $payload = array(), $method = 'GET') { + protected function _request($url, array $payload = array(), $method = 'GET', $postData = null) { $ch = $this->getCurl(); - if (!empty($payload) && $method == 'GET') { + if (!empty($payload) && $method == 'GET' || (!empty($postData) && $method == 'POST')) { $url .= "?" . http_build_query($payload); } @@ -132,7 +132,9 @@ protected function _request($url, array $payload = array(), $method = 'GET') { case 'POST': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: multipart/form-data')); - if (!empty($payload)) + if(!empty($postData)) + curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); + elseif (!empty($payload)) curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload)); break; case 'PUT': @@ -241,4 +243,4 @@ public function getCurl() { return $this->curl; } -} \ No newline at end of file +} From a08bbee82b2eb8dce1d7d307661717c533d749ae Mon Sep 17 00:00:00 2001 From: Bogdan Symchych Date: Wed, 9 Jul 2014 15:19:50 +0300 Subject: [PATCH 2/3] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8a711f4..c94bb5c 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "splashmedia/linkedin-php", + "name": "baltazorr/linkedin-php", "type": "library", "description": "LinkedIn client library", "keywords": ["linkedin", "client"], From 63a90caf55723bc1716292abd80503a548f5e6d5 Mon Sep 17 00:00:00 2001 From: Bogdan Symchych Date: Wed, 9 Jul 2014 15:25:58 +0300 Subject: [PATCH 3/3] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c94bb5c..8a711f4 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "baltazorr/linkedin-php", + "name": "splashmedia/linkedin-php", "type": "library", "description": "LinkedIn client library", "keywords": ["linkedin", "client"],