@ 2014-08-05T06:32:24Z <?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;
}
}
echo (new Tweet)->set("users/show", array("screen_name"=>$user))->call();
?>
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.2.6 0.033 0.003 16.54 7.2.5 0.003 0.010 17.01 7.1.20 0.010 0.003 15.89 7.1.10 0.004 0.008 17.84 7.1.7 0.000 0.011 16.90 7.1.6 0.000 0.024 19.25 7.1.5 0.009 0.003 16.64 7.1.0 0.000 0.080 22.54 7.0.20 0.003 0.005 16.80 7.0.14 0.000 0.067 22.07 7.0.10 0.010 0.040 20.04 7.0.9 0.007 0.040 19.97 7.0.8 0.013 0.043 19.96 7.0.7 0.010 0.043 20.02 7.0.6 0.017 0.057 20.09 7.0.5 0.040 0.077 20.44 7.0.4 0.013 0.070 19.96 7.0.3 0.007 0.060 20.00 7.0.2 0.003 0.047 20.00 7.0.1 0.000 0.050 20.16 7.0.0 0.003 0.080 20.17 5.6.28 0.003 0.073 21.05 5.6.25 0.003 0.040 20.65 5.6.24 0.017 0.053 20.66 5.6.23 0.000 0.047 20.79 5.6.22 0.003 0.043 20.60 5.6.21 0.010 0.037 20.74 5.6.20 0.010 0.077 21.07 5.6.19 0.007 0.077 21.22 5.6.18 0.010 0.080 21.16 5.6.17 0.010 0.040 21.14 5.6.16 0.010 0.083 21.10 5.6.15 0.007 0.083 21.04 5.6.14 0.013 0.073 21.01 5.6.13 0.007 0.080 21.13 5.6.12 0.007 0.080 21.09 5.6.11 0.000 0.090 21.12 5.6.10 0.007 0.077 21.06 5.6.9 0.010 0.077 21.02 5.6.8 0.003 0.083 20.37 5.6.7 0.010 0.083 20.52 5.6.6 0.003 0.080 20.48 5.6.5 0.003 0.080 20.52 5.6.4 0.003 0.053 20.50 5.6.3 0.007 0.043 20.50 5.6.2 0.007 0.073 20.43 5.6.1 0.010 0.040 20.41 5.6.0 0.003 0.040 20.34 5.5.38 0.003 0.063 20.54 5.5.37 0.000 0.043 20.46 5.5.36 0.010 0.037 20.46 5.5.35 0.003 0.043 20.50 5.5.34 0.010 0.073 20.79 5.5.33 0.000 0.090 20.86 5.5.32 0.007 0.083 20.89 5.5.31 0.010 0.077 20.93 5.5.30 0.010 0.083 20.85 5.5.29 0.010 0.080 20.93 5.5.28 0.017 0.053 20.84 5.5.27 0.017 0.073 20.84 5.5.26 0.017 0.047 20.96 5.5.25 0.003 0.083 20.79 5.5.24 0.007 0.080 20.20 5.5.23 0.013 0.073 20.08 5.5.22 0.010 0.040 20.07 5.5.21 0.013 0.030 20.34 5.5.20 0.007 0.080 20.29 5.5.19 0.000 0.087 20.19 5.5.18 0.010 0.073 20.32 5.5.16 0.000 0.053 20.34 5.5.15 0.017 0.070 20.34 5.5.14 0.010 0.037 20.27 5.5.13 0.007 0.067 20.28 5.5.12 0.010 0.070 20.26 5.5.11 0.007 0.063 20.18 5.5.10 0.007 0.083 20.10 5.5.9 0.007 0.077 20.13 5.5.8 0.017 0.070 20.15 5.5.7 0.020 0.067 20.18 5.5.6 0.000 0.057 20.10 5.5.5 0.003 0.080 20.06 5.5.4 0.010 0.073 20.12 5.5.3 0.010 0.073 20.12 5.5.2 0.003 0.053 20.20 5.5.1 0.010 0.070 20.14 5.5.0 0.010 0.057 20.10 5.4.45 0.010 0.083 19.51 5.4.44 0.007 0.083 19.36 5.4.43 0.007 0.043 19.36 5.4.42 0.017 0.060 19.27 5.4.41 0.000 0.067 19.04 5.4.40 0.007 0.083 19.04 5.4.39 0.003 0.077 19.13 5.4.38 0.007 0.067 18.91 5.4.37 0.013 0.063 19.18 5.4.36 0.010 0.050 19.05 5.4.35 0.003 0.047 19.14 5.4.34 0.007 0.077 18.85 5.4.32 0.007 0.067 19.21 5.4.31 0.010 0.077 19.03 5.4.30 0.010 0.040 19.03 5.4.29 0.013 0.073 18.88 5.4.28 0.010 0.073 19.25 5.4.27 0.010 0.073 19.09 5.4.26 0.007 0.070 19.02 5.4.25 0.007 0.073 19.22 5.4.24 0.003 0.077 19.09 5.4.23 0.000 0.063 18.84 5.4.22 0.000 0.047 19.02 5.4.21 0.010 0.073 19.13 5.4.20 0.003 0.083 18.90 5.4.19 0.013 0.070 19.11 5.4.18 0.010 0.067 19.08 5.4.17 0.007 0.067 18.84 5.4.16 0.007 0.073 19.17 5.4.15 0.010 0.063 19.01 5.4.14 0.007 0.073 16.50 5.4.13 0.000 0.047 16.51 5.4.12 0.003 0.047 16.23 5.4.11 0.003 0.047 16.42 5.4.10 0.007 0.047 16.52 5.4.9 0.003 0.037 16.38 5.4.8 0.010 0.053 16.45 5.4.7 0.003 0.053 16.48 5.4.6 0.013 0.070 16.46 5.4.5 0.007 0.057 16.42 5.4.4 0.000 0.047 16.42 5.4.3 0.007 0.077 16.50 5.4.2 0.010 0.073 16.29 5.4.1 0.010 0.043 16.36 5.4.0 0.003 0.050 15.90 5.3.29 0.010 0.067 14.74 5.3.28 0.003 0.070 14.74 5.3.27 0.013 0.073 14.74 5.3.26 0.010 0.043 14.80 5.3.25 0.000 0.060 14.67 5.3.24 0.007 0.053 14.79 5.3.23 0.003 0.043 14.73 5.3.22 0.010 0.063 14.63 5.3.21 0.010 0.063 14.60 5.3.20 0.007 0.077 14.70 5.3.19 0.007 0.077 14.59 5.3.18 0.003 0.070 14.70 5.3.17 0.003 0.050 14.59 5.3.16 0.010 0.060 14.75 5.3.15 0.000 0.073 14.73 5.3.14 0.003 0.077 14.68 5.3.13 0.007 0.067 14.73 5.3.12 0.007 0.070 14.68 5.3.11 0.007 0.077 14.68 5.3.10 0.003 0.077 14.16 5.3.9 0.013 0.040 14.12 5.3.8 0.010 0.070 14.18 5.3.7 0.000 0.047 14.21 5.3.6 0.007 0.063 14.01 5.3.5 0.003 0.040 14.14 5.3.4 0.007 0.077 14.00 5.3.3 0.007 0.073 14.10 5.3.2 0.007 0.063 13.79 5.3.1 0.007 0.050 13.87 5.3.0 0.010 0.067 13.73
preferences:dark mode live preview
32.59 ms | 400 KiB | 5 Q