You are here

class TwitterOAuth in Twitter 6.3

Same name and namespace in other branches
  1. 7.3 twitter.lib.php \TwitterOAuth

A class to provide OAuth enabled access to the twitter API

Hierarchy

Expanded class hierarchy of TwitterOAuth

1 string reference to 'TwitterOAuth'
twitter_fetch_user_timeline in ./twitter.inc
Fetches a user's timeline

File

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

View source
class TwitterOAuth extends Twitter {
  protected $signature_method;
  protected $consumer;
  protected $token;
  public function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) {
    $this->signature_method = new OAuthSignatureMethod_HMAC_SHA1();
    $this->consumer = new OAuthConsumer($consumer_key, $consumer_secret);
    if (!empty($oauth_token) && !empty($oauth_token_secret)) {
      $this->token = new OAuthConsumer($oauth_token, $oauth_token_secret);
    }
  }
  protected function create_oauth_url($path, $format = NULL) {
    if (is_null($format)) {
      $format = $this->format;
    }
    $conf = TwitterConf::instance();
    $url = 'http://' . $conf
      ->get('api') . '/' . $path;
    if (!empty($format)) {
      $url .= '.' . $this->format;
    }
    return $url;
  }
  public function get_request_token() {
    $url = $this
      ->create_oauth_url('oauth/request_token', '');
    try {
      $response = $this
        ->auth_request($url);
    } catch (TwitterException $e) {
    }
    parse_str($response, $token);
    $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
    return $token;
  }
  public function get_authorize_url($token) {
    $url = $this
      ->create_oauth_url('oauth/authorize', '');
    $url .= '?oauth_token=' . $token['oauth_token'];
    return $url;
  }
  public function get_authenticate_url($token) {
    $url = $this
      ->create_oauth_url('oauth/authenticate', '');
    $url .= '?oauth_token=' . $token['oauth_token'];
    return $url;
  }
  public function get_access_token() {
    $url = $this
      ->create_oauth_url('oauth/access_token', '');
    try {
      $response = $this
        ->auth_request($url);
    } catch (TwitterException $e) {
    }
    parse_str($response, $token);
    $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
    return $token;
  }
  public function auth_request($url, $params = array(), $method = 'GET') {
    $request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $method, $url, $params);
    $request
      ->sign_request($this->signature_method, $this->consumer, $this->token);
    switch ($method) {
      case 'GET':
        return $this
          ->request($request
          ->to_url());
      case 'POST':
        return $this
          ->request($request
          ->get_normalized_http_url(), $request
          ->get_parameters(), 'POST');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Twitter::$format protected property
Twitter::$password protected property
Twitter::$source protected property
Twitter::$username protected property
Twitter::call public function Calls a twitter api resource
Twitter::create_url protected function
Twitter::friends_timeline public function Fetch the authenticated user's friends timeline
Twitter::get_statuses protected function Get an array of TwitterStatus objects from an API endpoint
Twitter::mentions public function
Twitter::parse_response protected function
Twitter::public_timeline public function Fetch the public timeline
Twitter::request protected function Perform a request
Twitter::set_auth public function Set the username and password
Twitter::status_update public function Post a new status.
Twitter::users_show public function Returns profile information about a user.
Twitter::user_timeline public function Fetch a user's timeline
Twitter::verify_credentials public function
TwitterOAuth::$consumer protected property
TwitterOAuth::$signature_method protected property
TwitterOAuth::$token protected property
TwitterOAuth::auth_request public function Perform an authentication required request. Overrides Twitter::auth_request
TwitterOAuth::create_oauth_url protected function
TwitterOAuth::get_access_token public function
TwitterOAuth::get_authenticate_url public function
TwitterOAuth::get_authorize_url public function
TwitterOAuth::get_request_token public function
TwitterOAuth::__construct public function Constructor for the Twitter class Overrides Twitter::__construct