text
stringlengths 0
14.1k
|
---|
* Debug helpers |
*/ |
function lastStatusCode() { return $this->http_status; } |
function lastAPICall() { return $this->last_api_call; } |
/** |
* construct TwitterOAuth object |
*/ |
function __construct($consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL) { |
$this->sha1_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); |
} else { |
$this->token = NULL; |
} |
} |
/** |
* Get a request_token from Twitter |
* |
* @returns a key/value array containing oauth_token and oauth_token_secret |
*/ |
function getRequestToken($oauth_callback = NULL) { |
$parameters = array(); |
if (!empty($oauth_callback)) { |
$parameters['oauth_callback'] = $oauth_callback; |
} |
$request = $this->oAuthRequest($this->requestTokenURL(), 'GET', $parameters); |
$token = OAuthUtil::parse_parameters($request); |
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); |
return $token; |
} |
/** |
* Get the authorize URL |
* |
* @returns a string |
*/ |
function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) { |
if (is_array($token)) { |
$token = $token['oauth_token']; |
} |
if (empty($sign_in_with_twitter)) { |
return $this->authorizeURL() . ""?oauth_token={$token}""; |
} else { |
return $this->authenticateURL() . ""?oauth_token={$token}""; |
} |
} |
/** |
* Exchange request token and secret for an access token and |
* secret, to sign API calls. |
* |
* @returns array(""oauth_token"" => ""the-access-token"", |
* ""oauth_token_secret"" => ""the-access-secret"", |
* ""user_id"" => ""9436992"", |
* ""screen_name"" => ""abraham"") |
*/ |
function getAccessToken($oauth_verifier = FALSE) { |
$parameters = array(); |
if (!empty($oauth_verifier)) { |
$parameters['oauth_verifier'] = $oauth_verifier; |
} |
$request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters); |
$token = OAuthUtil::parse_parameters($request); |
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); |
return $token; |
} |
/** |
* One time exchange of username and password for access token and secret. |
* |
* @returns array(""oauth_token"" => ""the-access-token"", |
* ""oauth_token_secret"" => ""the-access-secret"", |
* ""user_id"" => ""9436992"", |
* ""screen_name"" => ""abraham"", |
* ""x_auth_expires"" => ""0"") |
*/ |
function getXAuthToken($username, $password) { |
$parameters = array(); |
$parameters['x_auth_username'] = $username; |
$parameters['x_auth_password'] = $password; |
$parameters['x_auth_mode'] = 'client_auth'; |
$request = $this->oAuthRequest($this->accessTokenURL(), 'POST', $parameters); |
$token = OAuthUtil::parse_parameters($request); |
$this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); |
return $token; |
} |
/** |
* GET wrapper for oAuthRequest. |
*/ |
function get($url, $parameters = array()) { |
$response = $this->oAuthRequest($url, 'GET', $parameters); |
if ($this->format === 'json' && $this->decode_json) { |
return json_decode($response); |
} |
return $response; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.