protected function getAccessToken()
    {
        $response = $this->httpClient
            ->post(
                self::ENDPOINT_ACCESS_TOKEN,
                array(
                    'grant_type'    => 'client_credentials',
                    'client_id'     => $this->config['client_id'],
                    'client_secret' => $this->config['client_secret'],
                    'scope'         => implode(',', $this->config['scopes'])
                )
            )
        ;

        $data = json_decode($response->getContent(), true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            $ex = new HttpResponseException('[access_token] Invalid JSON: '. json_last_error_msg());
            $ex
                ->setResponse($this->httpClient->getLastResponse())
                ->setRequest($this->httpClient->getLastRequest())
            ;

            throw $ex;
        }

        if (false === array_key_exists('access_token', $data)) {
            throw new HttpResponseException('access_token is missing from response. '. $response->getContent());
        }

        return $data;
    }
protected function getAccessToken()
    {
        $response = $this->httpClient
            ->post(
                self::ENDPOINT_ACCESS_TOKEN,
                array(
                    'grant_type'    => 'client_credentials',
                    'client_id'     => $this->config['client_id'],
                    'client_secret' => $this->config['client_secret'],
                    'scope'         => implode(',', $this->config['scopes'])
                )
            )
        ;

        $data = json_decode($response->getContent(), true);

        if (json_last_error() !== JSON_ERROR_NONE) {
            $ex = new HttpResponseException('[access_token] Invalid JSON: '. json_last_error_msg());
            $ex
                ->setResponse($this->httpClient->getLastResponse())
                ->setRequest($this->httpClient->getLastRequest())
            ;

            throw $ex;
        }

        if (false === array_key_exists('access_token', $data)) {
            throw new HttpResponseException('access_token is missing from response. '. $response->getContent());
        }

        return $data;
    }
protected function getAccessToken ( ) { $ response = $ this -> httpClient -> post ( self :: ENDPOINT_ACCESS_TOKEN , array ( 'grant_type' => 'client_credentials' , 'client_id' => $ this -> config [ 'client_id' ] , 'client_secret' => $ this -> config [ 'client_secret' ] , 'scope' => implode ( ',' , $ this -> config [ 'scopes' ] ) ) ) ; $ data = json_decode ( $ response -> getContent ( ) , true ) ; if ( json_last_error ( ) !== JSON_ERROR_NONE ) { $ ex = new HttpResponseException ( '[access_token] Invalid JSON: ' . json_last_error_msg ( ) ) ; $ ex -> setResponse ( $ this -> httpClient -> getLastResponse ( ) ) -> setRequest ( $ this -> httpClient -> getLastRequest ( ) ) ; throw $ ex ; } if ( false === array_key_exists ( 'access_token' , $ data ) ) { throw new HttpResponseException ( 'access_token is missing from response. ' . $ response -> getContent ( ) ) ; } return $ data ; }
Fetch access token with a grant_type of client_credentials

@access public
@return array

throws \InvalidArgumentException
@throws HttpResponseException
Fetch access token with a grant_type of client_credentials