Advertisement
Azathoth42

token

Jul 10th, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1.  
  2.     public function acquireAccessToken()
  3.     {
  4.         $params = [
  5.             'client_id' =>  $this->id,
  6.             'client_secret' => $this->secret,
  7.             'grant_type' => 'client_credentials'
  8.         ];
  9. //      $client = new GuzzleHttp\Client([
  10. //          'verify' => FALSE,
  11. //          'base_uri' => 'https://app.gosms.cz/'
  12. //      ]);
  13. //      try {
  14. ////            $request = new GuzzleHttp\Psr7\Request('post', 'oauth/v2/token');
  15. //          $response = $client->post('oauth/v2/token', $params);
  16. ////            $response = $client->send($request, $params);
  17. //          if ($response->getStatusCode() === 200) {
  18. //              $responseArray = $response->getBody();
  19. //              Debugger::barDump($responseArray, 'response body');
  20. //          } else {
  21. //              throw new InvalidStateException('App did not retrieve access token. Something is wrong.');
  22. //          }
  23. //      } catch (GuzzleHttp\Exception\ClientException $e) {
  24. //          Debugger::barDump($e->getRequest(), 'request');
  25. //          Debugger::barDump($e->getResponse(), 'error response');
  26. //          Debugger::barDump($e->getResponse()->getReasonPhrase(), 'reason');
  27. //      }
  28.  
  29.         $request = $this->createRequest('oauth/v2/token', FALSE);
  30.         try {
  31.             $response = $request->post($params);
  32.             $body = Json::decode($response->getResponse());
  33.             $this->accessToken = $body->access_token;
  34.             $this->cache->save('token', $this->accessToken, [
  35.                 Cache::EXPIRE => $body->expires_in
  36.             ]);
  37.         } catch(Curl\BadStatusException $e) {
  38.             Debugger::log($e);
  39.         }
  40.  
  41. //      $response = \Requests::post(self::BASE_URI.'oauth/v2/token', [], $params);
  42. ////        Debugger::barDump($response->body);
  43. //      $body = Json::decode($response->body);
  44. //      $this->accessToken = $body->access_token;
  45. //      $this->cache->save('token', $this->accessToken, [
  46. //          Cache::EXPIRE => $body->expires_in
  47. //      ]);
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement