@ 2014-08-05T06:33:32Z <?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);
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() {
return "lol";
}
}
echo (new Tweet)->set("users/show", array("screen_name"=>sarahlicity))->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.013 0.003 16.93 7.2.0 0.004 0.008 19.39 7.1.20 0.003 0.010 15.63 7.1.10 0.000 0.008 18.00 7.1.7 0.005 0.003 17.14 7.1.6 0.006 0.016 19.25 7.1.5 0.013 0.010 16.98 7.1.0 0.000 0.080 22.41 7.0.20 0.006 0.003 16.82 7.0.14 0.000 0.077 22.06 7.0.10 0.013 0.077 20.03 7.0.9 0.003 0.053 20.00 7.0.8 0.007 0.047 19.96 7.0.7 0.007 0.057 20.03 7.0.6 0.007 0.047 19.88 7.0.5 0.000 0.090 20.38 7.0.4 0.017 0.077 20.12 7.0.3 0.003 0.087 20.08 7.0.2 0.013 0.053 20.05 7.0.1 0.007 0.090 20.04 7.0.0 0.000 0.077 20.01 5.6.28 0.017 0.063 21.13 5.6.25 0.003 0.087 20.64 5.6.24 0.007 0.053 20.69 5.6.23 0.007 0.050 20.59 5.6.22 0.017 0.063 20.70 5.6.21 0.010 0.077 20.62 5.6.20 0.013 0.043 21.14 5.6.19 0.013 0.083 21.10 5.6.18 0.007 0.083 21.09 5.6.17 0.003 0.090 21.10 5.6.16 0.010 0.080 21.09 5.6.15 0.020 0.073 21.09 5.6.14 0.013 0.077 21.18 5.6.13 0.000 0.067 21.00 5.6.12 0.000 0.053 21.13 5.6.11 0.003 0.087 21.18 5.6.10 0.013 0.037 21.09 5.6.9 0.007 0.077 21.07 5.6.8 0.007 0.083 20.48 5.6.7 0.007 0.080 20.54 5.6.6 0.007 0.037 20.36 5.6.5 0.007 0.073 20.57 5.6.4 0.007 0.087 20.44 5.6.3 0.013 0.077 20.45 5.6.2 0.007 0.077 20.43 5.6.1 0.007 0.047 20.45 5.6.0 0.007 0.080 20.40 5.5.38 0.003 0.070 20.40 5.5.37 0.010 0.063 20.50 5.5.36 0.007 0.083 20.41 5.5.35 0.013 0.080 20.43 5.5.34 0.013 0.077 20.82 5.5.33 0.007 0.083 20.83 5.5.32 0.010 0.060 21.00 5.5.31 0.013 0.063 20.91 5.5.30 0.010 0.053 20.79 5.5.29 0.003 0.077 20.67 5.5.28 0.007 0.070 20.91 5.5.27 0.007 0.047 20.87 5.5.26 0.003 0.093 20.78 5.5.25 0.007 0.080 20.50 5.5.24 0.017 0.067 20.31 5.5.23 0.013 0.050 20.34 5.5.22 0.000 0.047 20.30 5.5.21 0.007 0.060 20.32 5.5.20 0.007 0.080 20.29 5.5.19 0.010 0.063 20.31 5.5.18 0.017 0.070 20.17 5.5.16 0.013 0.073 20.28 5.5.15 0.003 0.040 20.18 5.5.14 0.007 0.040 20.20 5.5.13 0.010 0.040 20.14 5.5.12 0.007 0.080 20.18 5.5.11 0.003 0.080 20.18 5.5.10 0.013 0.063 20.14 5.5.9 0.007 0.037 20.11 5.5.8 0.003 0.080 20.17 5.5.7 0.000 0.053 20.12 5.5.6 0.010 0.043 20.16 5.5.5 0.000 0.063 20.11 5.5.4 0.010 0.070 20.14 5.5.3 0.007 0.040 20.20 5.5.2 0.003 0.053 20.16 5.5.1 0.007 0.083 20.16 5.5.0 0.013 0.077 20.08 5.4.45 0.007 0.057 19.20 5.4.44 0.007 0.050 19.42 5.4.43 0.003 0.050 19.44 5.4.42 0.017 0.060 19.34 5.4.41 0.010 0.080 19.12 5.4.40 0.013 0.073 18.91 5.4.39 0.003 0.087 19.03 5.4.38 0.013 0.030 19.13 5.4.37 0.013 0.063 19.23 5.4.36 0.010 0.040 19.09 5.4.35 0.010 0.073 18.88 5.4.34 0.007 0.073 18.95 5.4.32 0.010 0.053 19.21 5.4.31 0.000 0.083 18.96 5.4.30 0.007 0.073 18.90 5.4.29 0.013 0.053 19.14 5.4.28 0.020 0.057 19.21 5.4.27 0.007 0.043 19.20 5.4.26 0.003 0.083 19.23 5.4.25 0.007 0.043 19.07 5.4.24 0.003 0.047 19.02 5.4.23 0.003 0.080 19.17 5.4.22 0.007 0.073 19.04 5.4.21 0.010 0.060 19.04 5.4.20 0.007 0.077 19.04 5.4.19 0.007 0.043 19.12 5.4.18 0.007 0.060 19.22 5.4.17 0.010 0.063 18.86 5.4.16 0.017 0.063 19.12 5.4.15 0.003 0.060 19.06 5.4.14 0.007 0.073 16.41 5.4.13 0.007 0.057 16.38 5.4.12 0.003 0.070 16.38 5.4.11 0.007 0.080 16.54 5.4.10 0.010 0.073 16.39 5.4.9 0.007 0.070 16.45 5.4.8 0.010 0.037 16.47 5.4.7 0.007 0.033 16.52 5.4.6 0.000 0.040 16.42 5.4.5 0.003 0.063 16.55 5.4.4 0.007 0.073 16.35 5.4.3 0.003 0.043 16.49 5.4.2 0.010 0.067 16.51 5.4.1 0.017 0.070 16.53 5.4.0 0.003 0.047 15.94 5.3.29 0.003 0.053 14.79 5.3.28 0.010 0.063 14.79 5.3.27 0.003 0.080 14.79 5.3.26 0.007 0.067 14.64 5.3.25 0.013 0.073 14.70 5.3.24 0.010 0.067 14.73 5.3.23 0.010 0.070 14.66 5.3.22 0.007 0.073 14.56 5.3.21 0.010 0.053 14.66 5.3.20 0.007 0.077 14.59 5.3.19 0.003 0.070 14.70 5.3.18 0.003 0.077 14.69 5.3.17 0.010 0.037 14.65 5.3.16 0.000 0.040 14.77 5.3.15 0.003 0.080 14.61 5.3.14 0.003 0.070 14.60 5.3.13 0.007 0.047 14.57 5.3.12 0.010 0.073 14.73 5.3.11 0.003 0.047 14.63 5.3.10 0.003 0.073 14.17 5.3.9 0.010 0.063 14.08 5.3.8 0.013 0.067 14.07 5.3.7 0.003 0.057 14.12 5.3.6 0.003 0.067 14.00 5.3.5 0.003 0.047 14.08 5.3.4 0.000 0.077 13.95 5.3.3 0.003 0.047 14.04 5.3.2 0.003 0.073 13.90 5.3.1 0.010 0.060 13.73 5.3.0 0.003 0.050 13.83
preferences:dark mode live preview
47.62 ms | 401 KiB | 5 Q