@@ -186,49 +186,49 @@ |
||
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // If access token is not set or token has expired, acquire new token |
| 189 | - if (empty($this->accessToken)){ |
|
| 190 | - $this->acquireAccessToken(); |
|
| 191 | - }else if($this->tokenHasExpired()){ |
|
| 192 | - $this->aquire_accesstoken_by_refreshtoken(); |
|
| 193 | - } |
|
| 189 | + if (empty($this->accessToken)){ |
|
| 190 | + $this->acquireAccessToken(); |
|
| 191 | + }else if($this->tokenHasExpired()){ |
|
| 192 | + $this->aquire_accesstoken_by_refreshtoken(); |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | 195 | $client = $this->client(); |
| 196 | 196 | |
| 197 | 197 | return $client; |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - // Refresh token when Token has Expired |
|
| 201 | - private function aquire_accesstoken_by_refreshtoken() { |
|
| 202 | - $headers = array("Content-Type: application/x-www-form-urlencoded", "Cache-Control: no-cache"); |
|
| 203 | - $params = array( |
|
| 204 | - 'refresh_token' => $this->refreshToken, |
|
| 205 | - 'grant_type' => 'refresh_token', |
|
| 206 | - 'client_id' => $this->exactClientId, |
|
| 200 | + // Refresh token when Token has Expired |
|
| 201 | + private function aquire_accesstoken_by_refreshtoken() { |
|
| 202 | + $headers = array("Content-Type: application/x-www-form-urlencoded", "Cache-Control: no-cache"); |
|
| 203 | + $params = array( |
|
| 204 | + 'refresh_token' => $this->refreshToken, |
|
| 205 | + 'grant_type' => 'refresh_token', |
|
| 206 | + 'client_id' => $this->exactClientId, |
|
| 207 | 207 | 'client_secret' => $this->exactClientSecret, |
| 208 | - ); |
|
| 209 | - |
|
| 210 | - $curl = curl_init(); |
|
| 211 | - $url = $this->getTokenUrl(); |
|
| 212 | - curl_setopt($curl, CURLOPT_URL,$url); |
|
| 213 | - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
| 214 | - curl_setopt($curl, CURLOPT_POST, true); |
|
| 215 | - curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($params)); |
|
| 216 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 217 | - $output = curl_exec ($curl); |
|
| 218 | - |
|
| 219 | - $res = json_decode($output, true); |
|
| 220 | - if(!$res['error'] && $res['refresh_token']){ |
|
| 221 | - $this->accessToken = $res['access_token']; |
|
| 222 | - $this->refreshToken = $res['refresh_token']; |
|
| 223 | - $this->tokenExpires = $this->getTimestampFromExpiresIn($res['expires_in']); |
|
| 224 | - |
|
| 225 | - if (is_callable($this->tokenUpdateCallback)) { |
|
| 226 | - call_user_func($this->tokenUpdateCallback, $this); |
|
| 227 | - } |
|
| 228 | - } else { |
|
| 229 | - throw new ApiException('Could not acquire tokens, json decode failed. Got response: ' . $res["error"] .', '. $res["error_description"]); |
|
| 230 | - } |
|
| 231 | - } |
|
| 208 | + ); |
|
| 209 | + |
|
| 210 | + $curl = curl_init(); |
|
| 211 | + $url = $this->getTokenUrl(); |
|
| 212 | + curl_setopt($curl, CURLOPT_URL,$url); |
|
| 213 | + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); |
|
| 214 | + curl_setopt($curl, CURLOPT_POST, true); |
|
| 215 | + curl_setopt($curl, CURLOPT_POSTFIELDS,http_build_query($params)); |
|
| 216 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 217 | + $output = curl_exec ($curl); |
|
| 218 | + |
|
| 219 | + $res = json_decode($output, true); |
|
| 220 | + if(!$res['error'] && $res['refresh_token']){ |
|
| 221 | + $this->accessToken = $res['access_token']; |
|
| 222 | + $this->refreshToken = $res['refresh_token']; |
|
| 223 | + $this->tokenExpires = $this->getTimestampFromExpiresIn($res['expires_in']); |
|
| 224 | + |
|
| 225 | + if (is_callable($this->tokenUpdateCallback)) { |
|
| 226 | + call_user_func($this->tokenUpdateCallback, $this); |
|
| 227 | + } |
|
| 228 | + } else { |
|
| 229 | + throw new ApiException('Could not acquire tokens, json decode failed. Got response: ' . $res["error"] .', '. $res["error_description"]); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | /** |
| 234 | 234 | * @param string $method |