/**
  * Perform an OAuth request - these differ somewhat from regular API calls
  * @internal
  */
 public function oauth_exchange($endpoint, array $args)
 {
     // build a post request and authenticate via OAuth header
     $params = new TwitterOAuthParams($args);
     $params->set_consumer($this->Consumer);
     if ($this->AccessToken) {
         $params->set_token($this->AccessToken);
     }
     $params->sign_hmac('POST', $endpoint);
     $conf = array('method' => 'POST', 'redirection' => 0, 'headers' => array('Authorization' => $params->oauth_header()));
     $http = self::http_request($endpoint, $conf);
     $body = trim($http['body']);
     $stat = $http['response']['code'];
     if (200 !== $stat) {
         throw new TwitterApiException($body, -1, $stat);
     }
     parse_str($body, $params);
     if (!is_array($params) || !isset($params['oauth_token']) || !isset($params['oauth_token_secret'])) {
         throw new TwitterApiException(__('Malformed response from Twitter', 'twitter-api'), -1, $stat);
     }
     return $params;
 }
 /**
  * Perform an OAuth request - these differ somewhat from regular API calls
  * @internal
  */
 private function oauth_exchange($endpoint, array $args)
 {
     // build a post request and authenticate via OAuth header
     $params = new TwitterOAuthParams($args);
     $params->set_consumer($this->Consumer);
     if ($this->AccessToken) {
         $params->set_token($this->AccessToken);
     }
     $params->sign_hmac('POST', $endpoint);
     $conf = array('method' => 'POST', 'headers' => array('Authorization' => $params->oauth_header()));
     $http = self::http_request($endpoint, $conf);
     $body = trim($http['body']);
     $stat = $http['status'];
     if (200 !== $stat) {
         // Twitter might respond as XML, but with an HTML content type for some reason
         if (0 === strpos($body, '<?')) {
             $xml = simplexml_load_string($body);
             $body = (string) $xml->error;
         }
         throw new TwitterApiException($body, -1, $stat);
     }
     parse_str($body, $params);
     if (!is_array($params) || !isset($params['oauth_token']) || !isset($params['oauth_token_secret'])) {
         throw new TwitterApiException('Malformed response from Twitter', -1, $stat);
     }
     return $params;
 }