function request_token() { $encoded_auth = base64_encode( $this->client_id . ":" . $this->client_secret ); $args = array( 'method' => 'POST', 'httpversion' => '1.1', 'headers' => array( 'Authorization' => 'Basic '. $encoded_auth, 'Content-Type' => 'application/x-www-form-urlencoded;charset=UTF-8', ), 'body' => 'grant_type=client_credentials', ); $response = wp_remote_post( $this->api_url, $args ); // If the status code is not 200, throw an error with the raw response body if ( isset( $response['response'] ) && $response['response']['code'] !== 200 ) { throw new RuntimeException( $response['response']['message'] ); } $token_response = json_decode( $response['body'] ); if( isset( $token_response->error ) ){ throw new RuntimeException( $token_response->error ); } return $token_response; }