Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function acquireAccessToken()
- {
- $params = [
- 'client_id' => $this->id,
- 'client_secret' => $this->secret,
- 'grant_type' => 'client_credentials'
- ];
- // $client = new GuzzleHttp\Client([
- // 'verify' => FALSE,
- // 'base_uri' => 'https://app.gosms.cz/'
- // ]);
- // try {
- //// $request = new GuzzleHttp\Psr7\Request('post', 'oauth/v2/token');
- // $response = $client->post('oauth/v2/token', $params);
- //// $response = $client->send($request, $params);
- // if ($response->getStatusCode() === 200) {
- // $responseArray = $response->getBody();
- // Debugger::barDump($responseArray, 'response body');
- // } else {
- // throw new InvalidStateException('App did not retrieve access token. Something is wrong.');
- // }
- // } catch (GuzzleHttp\Exception\ClientException $e) {
- // Debugger::barDump($e->getRequest(), 'request');
- // Debugger::barDump($e->getResponse(), 'error response');
- // Debugger::barDump($e->getResponse()->getReasonPhrase(), 'reason');
- // }
- $request = $this->createRequest('oauth/v2/token', FALSE);
- try {
- $response = $request->post($params);
- $body = Json::decode($response->getResponse());
- $this->accessToken = $body->access_token;
- $this->cache->save('token', $this->accessToken, [
- Cache::EXPIRE => $body->expires_in
- ]);
- } catch(Curl\BadStatusException $e) {
- Debugger::log($e);
- }
- // $response = \Requests::post(self::BASE_URI.'oauth/v2/token', [], $params);
- //// Debugger::barDump($response->body);
- // $body = Json::decode($response->body);
- // $this->accessToken = $body->access_token;
- // $this->cache->save('token', $this->accessToken, [
- // Cache::EXPIRE => $body->expires_in
- // ]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement