Skip to content

Instantly share code, notes, and snippets.

@ajace
Created August 5, 2013 14:22
Show Gist options
  • Save ajace/6156284 to your computer and use it in GitHub Desktop.
Save ajace/6156284 to your computer and use it in GitHub Desktop.
Twitter Api v1.1
public function curl_fetch ( $id, $since ) {
/*** Twitter Api v1.1 ***/
$url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
$count = $this->_app->count;
$sinceUrl = $since != false ? "&since_id={$since}" : '';
$oauth_access_token = $this->_app->oauth_access_token;
$oauth_access_token_secret = $this->_app->oauth_access_token_secret;
$consumer_key = $this->_app->consumer_key;
$consumer_secret = $this->_app->consumer_secret;
$oauth = array(
'screen_name' => $id,
'count' => $count,
'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');
if ($since != false) { $oauth['since_id'] = $since; }
$base_info = $this->buildBaseString($url, 'GET', $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;
// Make Requests
$header = array($this->buildAuthorizationHeader($oauth), 'Expect:');
$options = array( CURLOPT_HTTPHEADER => $header,
//CURLOPT_POSTFIELDS => $postfields,
CURLOPT_HEADER => false,
CURLOPT_URL => $url . '?screen_name=' . $id . '&count=' . $count . $sinceUrl,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
$json = curl_exec($feed);
curl_close($feed);
return json_decode($json);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment