src/OAuth.php
public function getResponse($code, $forceNew = false)
  {
      if (!$this->oauthResponse || $forceNew) {
          $form_params = [
        'client_id'       => $this->getClientId(),
        'client_secret'   => $this->clientSecret,
        'grant_type'      => 'authorization_code',
        'redirect_uri'    => $this->getRedirectUri(),
        'code'            => $code,
        'state'           => $this->getState(),
      ];

          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $this->authURL);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $form_params);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
          $result = curl_exec($ch);
          curl_close($ch);

          $data = json_decode($result, true);
          if (json_last_error() != JSON_ERROR_NONE) {
              throw new \UnexpectedValueException('Received data is not json');

              return;
          }

          $status = $data['status'];

          if (strrpos($status, 20, -strlen($status)) === false) {
              throw new Exceptions\BadResponseException('Received bad response ('.$data['status'].'): '.$data['message']);

              return;
          }

          $this->OAuthResponse = new OAuthResponse($data);
      }

      return $this->OAuthResponse;
  }
public function getResponse($code, $forceNew = false)
  {
      if (!$this->oauthResponse || $forceNew) {
          $form_params = [
        'client_id'       => $this->getClientId(),
        'client_secret'   => $this->clientSecret,
        'grant_type'      => 'authorization_code',
        'redirect_uri'    => $this->getRedirectUri(),
        'code'            => $code,
        'state'           => $this->getState(),
      ];

          $ch = curl_init();
          curl_setopt($ch, CURLOPT_URL, $this->authURL);
          curl_setopt($ch, CURLOPT_POST, true);
          curl_setopt($ch, CURLOPT_POSTFIELDS, $form_params);
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
          curl_setopt($crl, CURLOPT_CONNECTTIMEOUT, 5);
          $result = curl_exec($ch);
          curl_close($ch);

          $data = json_decode($result, true);
          if (json_last_error() != JSON_ERROR_NONE) {
              throw new \UnexpectedValueException('Received data is not json');

              return;
          }

          $status = $data['status'];

          if (strrpos($status, 20, -strlen($status)) === false) {
              throw new Exceptions\BadResponseException('Received bad response ('.$data['status'].'): '.$data['message']);

              return;
          }

          $this->OAuthResponse = new OAuthResponse($data);
      }

      return $this->OAuthResponse;
  }
public function getResponse ( $ code , $ forceNew = false ) { if ( ! $ this -> oauthResponse || $ forceNew ) { $ form_params = [ 'client_id' => $ this -> getClientId ( ) , 'client_secret' => $ this -> clientSecret , 'grant_type' => 'authorization_code' , 'redirect_uri' => $ this -> getRedirectUri ( ) , 'code' => $ code , 'state' => $ this -> getState ( ) , ] ; $ ch = curl_init ( ) ; curl_setopt ( $ ch , CURLOPT_URL , $ this -> authURL ) ; curl_setopt ( $ ch , CURLOPT_POST , true ) ; curl_setopt ( $ ch , CURLOPT_POSTFIELDS , $ form_params ) ; curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ crl , CURLOPT_CONNECTTIMEOUT , 5 ) ; $ result = curl_exec ( $ ch ) ; curl_close ( $ ch ) ; $ data = json_decode ( $ result , true ) ; if ( json_last_error ( ) != JSON_ERROR_NONE ) { throw new \ UnexpectedValueException ( 'Received data is not json' ) ; return ; } $ status = $ data [ 'status' ] ; if ( strrpos ( $ status , 20 , - strlen ( $ status ) ) === false ) { throw new Exceptions \ BadResponseException ( 'Received bad response (' . $ data [ 'status' ] . '): ' . $ data [ 'message' ] ) ; return ; } $ this -> OAuthResponse = new OAuthResponse ( $ data ) ; } return $ this -> OAuthResponse ; }
Returns the OAuthResponse object that contains the access_token, registered scopes
and the refresh_token.

@param  string $code     Code returned by OAuth
@param  bool $forceNew Force new token

@return Raideer\TwitchApi\OAuthResponse
Returns the OAuthResponse object that contains the access_token registered scopes and the refresh_token .