@ 2014-08-05T06:30:28Z <?php
/**
* Twitter-API-PHP : Simple PHP wrapper for the v1.1 API
*
* PHP version 5.3.10
*
* @category Awesomeness
* @package Twitter-API-PHP
* @author James Mallison <me@j7mbo.co.uk>
* @license MIT License
* @link http://github.com/j7mbo/twitter-api-php
*/
class TwitterAPIExchange
{
private $oauth_access_token;
private $oauth_access_token_secret;
private $consumer_key;
private $consumer_secret;
private $postfields;
private $getfield;
protected $oauth;
public $url;
/**
* Create the API access object. Requires an array of settings::
* oauth access token, oauth access token secret, consumer key, consumer secret
* These are all available by creating your own application on dev.twitter.com
* Requires the cURL library
*
* @param array $settings
*/
public function __construct(array $settings)
{
if (!in_array('curl', get_loaded_extensions()))
{
throw new Exception('You need to install cURL, see: http://curl.haxx.se/docs/install.html');
}
if (!isset($settings['oauth_access_token'])
|| !isset($settings['oauth_access_token_secret'])
|| !isset($settings['consumer_key'])
|| !isset($settings['consumer_secret']))
{
throw new Exception('Make sure you are passing in the correct parameters');
}
$this->oauth_access_token = $settings['oauth_access_token'];
$this->oauth_access_token_secret = $settings['oauth_access_token_secret'];
$this->consumer_key = $settings['consumer_key'];
$this->consumer_secret = $settings['consumer_secret'];
}
/**
* Set postfields array, example: array('screen_name' => 'J7mbo')
*
* @param array $array Array of parameters to send to API
*
* @return TwitterAPIExchange Instance of self for method chaining
*/
public function setPostfields(array $array)
{
if (!is_null($this->getGetfield()))
{
throw new Exception('You can only choose get OR post fields.');
}
if (isset($array['status']) && substr($array['status'], 0, 1) === '@')
{
$array['status'] = sprintf("\0%s", $array['status']);
}
$this->postfields = $array;
return $this;
}
/**
* Set getfield string, example: '?screen_name=J7mbo'
*
* @param string $string Get key and value pairs as string
*
* @return \TwitterAPIExchange Instance of self for method chaining
*/
public function setGetfield($string)
{
if (!is_null($this->getPostfields()))
{
throw new Exception('You can only choose get OR post fields.');
}
$search = array('#', ',', '+', ':');
$replace = array('%23', '%2C', '%2B', '%3A');
$string = str_replace($search, $replace, $string);
$this->getfield = $string;
return $this;
}
/**
* Get getfield string (simple getter)
*
* @return string $this->getfields
*/
public function getGetfield()
{
return $this->getfield;
}
/**
* Get postfields array (simple getter)
*
* @return array $this->postfields
*/
public function getPostfields()
{
return $this->postfields;
}
/**
* Build the Oauth object using params set in construct and additionals
* passed to this method. For v1.1, see: https://dev.twitter.com/docs/api/1.1
*
* @param string $url The API url to use. Example: https://api.twitter.com/1.1/search/tweets.json
* @param string $requestMethod Either POST or GET
* @return \TwitterAPIExchange Instance of self for method chaining
*/
public function buildOauth($url, $requestMethod)
{
if (!in_array(strtolower($requestMethod), array('post', 'get')))
{
throw new Exception('Request method must be either POST or GET');
}
$consumer_key = $this->consumer_key;
$consumer_secret = $this->consumer_secret;
$oauth_access_token = $this->oauth_access_token;
$oauth_access_token_secret = $this->oauth_access_token_secret;
$oauth = array(
'oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.0'
);
$getfield = $this->getGetfield();
if (!is_null($getfield))
{
$getfields = str_replace('?', '', explode('&', $getfield));
foreach ($getfields as $g)
{
$split = explode('=', $g);
$oauth[$split[0]] = $split[1];
}
}
$base_info = $this->buildBaseString($url, $requestMethod, $oauth);
$composite_key = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);
$oauth_signature = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));
$oauth['oauth_signature'] = $oauth_signature;
$this->url = $url;
$this->oauth = $oauth;
return $this;
}
/**
* Perform the actual data retrieval from the API
*
* @param boolean $return If true, returns data.
*
* @return string json If $return param is true, returns json data.
*/
public function performRequest($return = true)
{
if (!is_bool($return))
{
throw new Exception('performRequest parameter must be true or false');
}
$header = array($this->buildAuthorizationHeader($this->oauth), 'Expect:');
$getfield = $this->getGetfield();
$postfields = $this->getPostfields();
$options = array(
CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $this->url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
);
if (!is_null($postfields))
{
$options[CURLOPT_POSTFIELDS] = $postfields;
}
else
{
if ($getfield !== '')
{
$options[CURLOPT_URL] .= $getfield;
}
}
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
if ($return) { return $json; }
}
/**
* Private method to generate the base string used by cURL
*
* @param string $baseURI
* @param string $method
* @param array $params
*
* @return string Built base string
*/
private function buildBaseString($baseURI, $method, $params)
{
$return = array();
ksort($params);
foreach($params as $key=>$value)
{
$return[] = "$key=" . $value;
}
return $method . "&" . rawurlencode($baseURI) . '&' . rawurlencode(implode('&', $return));
}
/**
* Private method to generate authorization header used by cURL
*
* @param array $oauth Array of oauth data generated by buildOauth()
*
* @return string $return Header used by cURL for request
*/
private function buildAuthorizationHeader($oauth)
{
$return = 'Authorization: OAuth ';
$values = array();
foreach($oauth as $key => $value)
{
$values[] = "$key=\"" . rawurlencode($value) . "\"";
}
$return .= implode(', ', $values);
return $return;
}
}
class Tweet extends TwitterAPIExchange {
//Enter your details here
const oauth_token = "16127841-XhE5Xlw8bArFmSyouf4y9AHx9KUJ2SrpL95994QV0";
const oauth_secret = "wtmbZlSntIXpKqiq4mIDmY1JqqmsIP6FCy1UyHRI9DuJ6";
const consumer_key = "hccV6YwzcYC9bjaTnbC6W6h2D";
const consumer_secret = "OucJEZ0GR6PgGSHZje0DLSmGdSmyXx9b0CWiSGVwla1jzApSdM";
public $json;
public $get;
private $twitter;
public function __construct() {
$settings = array('oauth_access_token' => self::oauth_token,
'oauth_access_token_secret' => self::oauth_secret,
'consumer_key' => self::consumer_key,
'consumer_secret' => self::consumer_secret);
$this->twitter = new TwitterAPIExchange($settings);
return $this;
}
public function set($json, $get) {
$this->json = "https://api.twitter.com/1.1/".$json.".json";
if(is_array($get)) {
$this->get = http_build_query($get);
} else {
$this->get = $get;
}
return $this;
}
public function call() {
$response=$this->twitter->setGetfield("?".$this->get)
->buildOauth($this->json, "GET")
->performRequest();
$response=json_decode($response, true);
return (array) $response;
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.0 0.003 0.014 14.88 7.3.12 0.007 0.011 15.11 7.3.11 0.013 0.006 14.63 7.3.10 0.000 0.014 14.75 7.3.9 0.007 0.007 14.70 7.3.8 0.004 0.011 14.83 7.3.7 0.013 0.000 14.63 7.3.6 0.004 0.011 14.59 7.3.5 0.007 0.010 14.71 7.3.4 0.007 0.010 14.66 7.3.3 0.013 0.006 14.79 7.3.2 0.004 0.015 16.58 7.3.1 0.004 0.011 16.39 7.3.0 0.006 0.009 16.32 7.2.25 0.017 0.000 15.13 7.2.24 0.010 0.010 14.80 7.2.23 0.004 0.008 15.17 7.2.22 0.003 0.010 15.07 7.2.21 0.000 0.016 14.48 7.2.20 0.003 0.007 14.87 7.2.19 0.003 0.013 14.91 7.2.18 0.009 0.003 14.86 7.2.17 0.010 0.010 14.66 7.2.0 0.003 0.006 19.06 7.1.33 0.007 0.007 15.68 7.1.32 0.004 0.008 15.73 7.1.31 0.005 0.005 15.57 7.1.30 0.010 0.003 15.68 7.1.29 0.006 0.006 15.40 7.1.28 0.008 0.012 15.34 7.1.27 0.003 0.015 15.69 7.1.26 0.003 0.010 15.53 7.1.10 0.003 0.009 17.90 7.1.7 0.000 0.009 16.88 7.1.6 0.009 0.013 19.25 7.1.5 0.014 0.011 16.89 7.1.0 0.007 0.073 22.46 7.0.20 0.004 0.004 16.67 7.0.14 0.003 0.077 22.08 7.0.8 0.003 0.053 20.00 7.0.7 0.063 0.073 20.02 7.0.6 0.010 0.060 20.02 7.0.5 0.013 0.067 20.44 7.0.4 0.010 0.080 20.11 7.0.3 0.007 0.087 20.18 7.0.2 0.020 0.060 20.15 7.0.1 0.010 0.047 20.18 7.0.0 0.013 0.080 20.14 5.6.28 0.010 0.070 21.10 5.6.23 0.010 0.080 20.59 5.6.22 0.003 0.087 20.54 5.6.21 0.000 0.090 20.61 5.6.20 0.007 0.077 21.15 5.6.19 0.003 0.050 20.99 5.6.18 0.017 0.073 21.16 5.6.17 0.007 0.083 21.07 5.6.16 0.010 0.077 21.19 5.6.15 0.003 0.063 20.99 5.6.14 0.020 0.073 21.22 5.6.13 0.013 0.080 21.11 5.6.12 0.007 0.080 21.05 5.6.11 0.017 0.067 21.02 5.6.10 0.010 0.070 21.04 5.6.9 0.010 0.067 21.05 5.6.8 0.017 0.060 20.46 5.6.7 0.003 0.083 20.56 5.6.6 0.007 0.073 20.36 5.6.5 0.007 0.083 20.37 5.6.4 0.013 0.040 20.48 5.6.3 0.010 0.067 20.43 5.6.2 0.007 0.083 20.46 5.6.1 0.013 0.077 20.44 5.6.0 0.003 0.083 20.43 5.5.37 0.007 0.040 20.41 5.5.36 0.010 0.080 20.39 5.5.35 0.010 0.080 20.50 5.5.34 0.003 0.053 20.95 5.5.33 0.007 0.083 20.96 5.5.32 0.007 0.083 20.90 5.5.31 0.007 0.087 20.96 5.5.30 0.003 0.043 20.94 5.5.29 0.000 0.087 20.81 5.5.28 0.007 0.080 20.82 5.5.27 0.003 0.090 20.95 5.5.26 0.017 0.073 20.91 5.5.25 0.000 0.050 20.78 5.5.24 0.003 0.070 20.31 5.5.23 0.007 0.050 20.36 5.5.22 0.003 0.060 20.23 5.5.21 0.010 0.080 20.21 5.5.20 0.017 0.067 20.27 5.5.19 0.003 0.087 20.16 5.5.18 0.017 0.067 20.33 5.5.16 0.027 0.063 20.32 5.5.15 0.010 0.073 20.30 5.5.14 0.010 0.073 20.32 5.5.13 0.000 0.080 20.26 5.5.12 0.020 0.060 20.25 5.5.11 0.007 0.077 20.12 5.5.10 0.007 0.080 20.15 5.5.9 0.023 0.063 20.20 5.5.8 0.003 0.057 20.23 5.5.7 0.013 0.073 20.15 5.5.6 0.017 0.070 20.10 5.5.5 0.007 0.077 20.10 5.5.4 0.010 0.063 20.20 5.5.3 0.007 0.047 20.13 5.5.2 0.007 0.047 20.13 5.5.1 0.003 0.043 20.18 5.5.0 0.007 0.043 20.01 5.4.45 0.007 0.083 19.57 5.4.44 0.007 0.087 19.38 5.4.43 0.007 0.057 19.36 5.4.42 0.010 0.043 19.48 5.4.41 0.003 0.057 19.14 5.4.40 0.010 0.073 19.14 5.4.39 0.003 0.080 18.86 5.4.38 0.000 0.050 19.05 5.4.37 0.010 0.077 19.18 5.4.36 0.000 0.087 19.13 5.4.35 0.003 0.077 19.16 5.4.34 0.007 0.060 19.03 5.4.32 0.013 0.070 18.93 5.4.31 0.007 0.073 18.90 5.4.30 0.010 0.077 19.20 5.4.29 0.003 0.077 19.11 5.4.28 0.007 0.057 19.18 5.4.27 0.007 0.057 19.20 5.4.26 0.017 0.057 19.24 5.4.25 0.003 0.073 19.13 5.4.24 0.013 0.070 19.25 5.4.23 0.010 0.070 19.13 5.4.22 0.007 0.047 18.91 5.4.21 0.013 0.070 19.15 5.4.20 0.007 0.050 19.24 5.4.19 0.007 0.070 18.94 5.4.18 0.003 0.083 18.84 5.4.17 0.003 0.077 19.20 5.4.16 0.013 0.073 19.18 5.4.15 0.007 0.067 19.01 5.4.14 0.010 0.070 16.55 5.4.13 0.010 0.067 16.38 5.4.12 0.003 0.037 16.55 5.4.11 0.010 0.073 16.48 5.4.10 0.013 0.063 16.34 5.4.9 0.000 0.067 16.55 5.4.8 0.013 0.067 16.47 5.4.7 0.010 0.037 16.43 5.4.6 0.007 0.033 16.46 5.4.5 0.003 0.060 16.46 5.4.4 0.003 0.070 16.46 5.4.3 0.010 0.053 16.54 5.4.2 0.003 0.043 16.45 5.4.1 0.003 0.073 16.36 5.4.0 0.007 0.040 15.95 5.3.29 0.003 0.070 14.66 5.3.28 0.010 0.037 14.80 5.3.27 0.003 0.043 14.59 5.3.26 0.013 0.043 14.71 5.3.25 0.010 0.073 14.63 5.3.24 0.017 0.070 14.70 5.3.23 0.017 0.050 14.59 5.3.22 0.007 0.040 14.70 5.3.21 0.003 0.070 14.68 5.3.20 0.007 0.073 14.61 5.3.19 0.007 0.070 14.56 5.3.18 0.000 0.053 14.68 5.3.17 0.007 0.063 14.70 5.3.16 0.007 0.067 14.58 5.3.15 0.010 0.043 14.70 5.3.14 0.010 0.037 14.68 5.3.13 0.007 0.080 14.75 5.3.12 0.007 0.073 14.63 5.3.11 0.003 0.063 14.58 5.3.10 0.007 0.053 14.04 5.3.9 0.003 0.087 14.11 5.3.8 0.007 0.073 14.06 5.3.7 0.007 0.077 14.18 5.3.6 0.003 0.043 14.09 5.3.5 0.003 0.060 13.92 5.3.4 0.007 0.073 14.13 5.3.3 0.010 0.067 13.90 5.3.2 0.003 0.047 13.87 5.3.1 0.010 0.067 13.79 5.3.0 0.007 0.073 13.75
preferences:dark mode live preview
36.75 ms | 401 KiB | 5 Q