You are here

protected function Twitter::request in Twitter 7.3

Same name and namespace in other branches
  1. 6.5 twitter.lib.php \Twitter::request()
  2. 6.3 twitter.lib.php \Twitter::request()
  3. 7.6 twitter.lib.php \Twitter::request()
  4. 7.5 twitter.lib.php \Twitter::request()

Perform a request

Throws

TwitterException

3 calls to Twitter::request()
Twitter::auth_request in ./twitter.lib.php
Perform an authentication required request.
Twitter::call in ./twitter.lib.php
Calls a twitter api resource
TwitterOAuth::auth_request in ./twitter.lib.php
Perform an authentication required request.

File

./twitter.lib.php, line 210
Classes to implement the full Twitter API

Class

Twitter
Primary Twitter API implementation class Supports the full REST API for twitter.

Code

protected function request($url, $params = array(), $method = 'GET', $use_auth = FALSE) {
  $data = '';
  if (count($params) > 0) {
    if ($method == 'GET') {
      $url .= '?' . http_build_query($params, '', '&');
    }
    else {
      $data = http_build_query($params, '', '&');
    }
  }
  $headers = array();
  if ($use_auth) {
    $headers['Authorization'] = 'Basic ' . base64_encode($this->username . ':' . $this->password);
    $headers['Content-type'] = 'application/x-www-form-urlencoded';
  }
  $response = drupal_http_request($url, array(
    'headers' => $headers,
    'method' => $method,
    'data' => $data,
  ));
  if (!isset($response->error)) {
    return $response->data;
  }
  else {
    $error = 'Unknown error.';
    if (isset($response->error)) {
      $error = $response->error;
    }
    if (isset($response->data) && ($data = $this
      ->parse_response($response->data))) {
      if (is_array($data)) {
        if (isset($data['errors'][0]['message'])) {
          $error = $data['errors'][0]['message'];
        }
        elseif (isset($data['error'])) {
          $error = $data['error'];
        }
      }
    }
    throw new TwitterException($error);
  }
}