@ 2014-08-05T06:33:06Z <?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() {
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.11 0.020 0.010 16.54 7.2.6 0.003 0.009 16.89 7.2.0 0.006 0.006 19.32 7.1.20 0.003 0.009 15.58 7.1.7 0.000 0.007 16.86 7.1.6 0.004 0.018 17.00 7.1.5 0.011 0.000 17.03 7.1.0 0.003 0.077 22.43 7.0.20 0.004 0.008 16.53 7.0.14 0.010 0.067 22.09 7.0.9 0.013 0.073 19.98 7.0.8 0.030 0.080 19.97 7.0.7 0.010 0.067 19.96 7.0.6 0.003 0.087 19.98 7.0.5 0.010 0.050 20.42 7.0.4 0.003 0.060 20.00 7.0.3 0.010 0.040 20.13 7.0.2 0.010 0.033 20.00 7.0.1 0.010 0.033 20.18 7.0.0 0.003 0.043 20.01 5.6.28 0.003 0.073 21.13 5.6.24 0.017 0.073 20.61 5.6.23 0.007 0.080 20.64 5.6.22 0.013 0.073 20.56 5.6.21 0.007 0.053 20.46 5.6.20 0.017 0.073 21.11 5.6.19 0.007 0.083 21.16 5.6.18 0.007 0.053 21.13 5.6.17 0.003 0.043 20.98 5.6.16 0.007 0.047 21.23 5.6.15 0.003 0.043 21.16 5.6.14 0.003 0.043 21.11 5.6.13 0.003 0.047 21.07 5.6.12 0.010 0.037 21.13 5.6.11 0.007 0.050 20.99 5.6.10 0.010 0.043 21.07 5.6.9 0.000 0.047 21.11 5.6.8 0.003 0.040 20.40 5.6.7 0.017 0.050 20.44 5.6.6 0.003 0.037 20.44 5.6.5 0.003 0.040 20.52 5.6.4 0.007 0.033 20.49 5.6.3 0.007 0.037 20.46 5.6.2 0.003 0.043 20.49 5.6.1 0.007 0.057 20.52 5.6.0 0.007 0.033 20.41 5.5.38 0.013 0.077 20.35 5.5.37 0.007 0.073 20.46 5.5.36 0.020 0.077 20.35 5.5.35 0.003 0.050 20.43 5.5.34 0.013 0.077 20.93 5.5.33 0.003 0.083 20.98 5.5.32 0.010 0.037 20.98 5.5.31 0.003 0.050 20.96 5.5.30 0.007 0.040 20.82 5.5.29 0.003 0.043 20.83 5.5.28 0.003 0.040 20.92 5.5.27 0.007 0.040 20.78 5.5.26 0.007 0.040 20.87 5.5.25 0.007 0.040 20.67 5.5.24 0.013 0.063 20.36 5.5.23 0.023 0.063 20.27 5.5.22 0.007 0.073 20.32 5.5.21 0.007 0.040 20.32 5.5.20 0.000 0.043 20.28 5.5.19 0.003 0.040 20.17 5.5.18 0.000 0.057 20.30 5.5.16 0.013 0.030 20.20 5.5.15 0.003 0.070 20.04 5.5.14 0.003 0.043 20.25 5.5.13 0.003 0.040 20.20 5.5.12 0.000 0.043 20.23 5.5.11 0.010 0.033 20.17 5.5.10 0.003 0.040 20.19 5.5.9 0.007 0.033 20.12 5.5.8 0.000 0.043 20.16 5.5.7 0.003 0.047 19.99 5.5.6 0.000 0.040 20.14 5.5.5 0.000 0.040 20.06 5.5.4 0.013 0.030 20.11 5.5.3 0.003 0.040 20.11 5.5.2 0.000 0.043 20.20 5.5.1 0.007 0.040 20.09 5.5.0 0.007 0.077 20.08 5.4.45 0.007 0.040 19.26 5.4.44 0.003 0.040 19.45 5.4.43 0.000 0.063 19.35 5.4.42 0.003 0.043 19.37 5.4.41 0.003 0.043 19.18 5.4.40 0.010 0.030 18.88 5.4.39 0.003 0.037 19.21 5.4.38 0.003 0.043 19.03 5.4.37 0.000 0.037 19.18 5.4.36 0.007 0.030 19.09 5.4.35 0.003 0.037 19.02 5.4.34 0.007 0.037 18.97 5.4.32 0.000 0.037 19.13 5.4.31 0.003 0.033 18.93 5.4.30 0.007 0.030 19.03 5.4.29 0.010 0.050 19.01 5.4.28 0.000 0.047 19.09 5.4.27 0.003 0.037 19.08 5.4.26 0.003 0.047 18.88 5.4.25 0.007 0.033 19.02 5.4.24 0.010 0.060 19.01 5.4.23 0.007 0.040 19.20 5.4.22 0.007 0.033 18.86 5.4.21 0.000 0.040 18.87 5.4.20 0.000 0.053 19.02 5.4.19 0.003 0.037 19.01 5.4.18 0.003 0.037 19.06 5.4.17 0.003 0.073 19.20 5.4.16 0.010 0.067 18.91 5.4.15 0.020 0.063 19.16 5.4.14 0.010 0.057 16.50 5.4.13 0.007 0.077 16.43 5.4.12 0.007 0.077 16.32 5.4.11 0.003 0.073 16.55 5.4.10 0.010 0.077 16.43 5.4.9 0.010 0.037 16.44 5.4.8 0.007 0.073 16.48 5.4.7 0.007 0.047 16.37 5.4.6 0.003 0.080 16.38 5.4.5 0.007 0.073 16.46 5.4.4 0.007 0.037 16.36 5.4.3 0.017 0.060 16.34 5.4.2 0.010 0.063 16.33 5.4.1 0.013 0.070 16.34 5.4.0 0.003 0.057 15.87 5.3.29 0.003 0.040 14.88 5.3.28 0.003 0.033 14.72 5.3.27 0.000 0.043 14.65 5.3.26 0.003 0.083 14.67 5.3.25 0.003 0.080 14.64 5.3.24 0.007 0.040 14.70 5.3.23 0.003 0.073 14.73 5.3.22 0.007 0.073 14.61 5.3.21 0.007 0.077 14.70 5.3.20 0.007 0.070 14.59 5.3.19 0.000 0.080 14.63 5.3.18 0.013 0.060 14.56 5.3.17 0.000 0.077 14.64 5.3.16 0.010 0.073 14.52 5.3.15 0.003 0.077 14.57 5.3.14 0.007 0.070 14.74 5.3.13 0.003 0.080 14.71 5.3.12 0.013 0.047 14.68 5.3.11 0.007 0.067 14.71 5.3.10 0.007 0.073 14.17 5.3.9 0.000 0.073 14.14 5.3.8 0.007 0.040 14.20 5.3.7 0.007 0.070 14.14 5.3.6 0.003 0.037 14.02 5.3.5 0.010 0.070 14.07 5.3.4 0.003 0.050 14.04 5.3.3 0.010 0.073 13.96 5.3.2 0.000 0.067 13.69 5.3.1 0.007 0.070 13.79 5.3.0 0.003 0.070 13.76
preferences:dark mode live preview
34.63 ms | 401 KiB | 5 Q