Advertisement
Guest User

Untitled

a guest
Feb 8th, 2013
500
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. function getTimeline() {
  2.         $CONSUMER_KEY           = "";
  3.         $CONSUMER_SECRET        = "";
  4.         $ACCESS_TOKEN           = "";
  5.         $ACCESS_TOKEN_SECRET        = "";
  6.  
  7.         $oauth_hash = '';
  8.         $oauth_hash .= 'oauth_consumer_key=' . $CONSUMER_KEY .'&';
  9.         $oauth_hash .= 'oauth_nonce=' . time() . '&';
  10.         $oauth_hash .= 'oauth_signature_method=HMAC-SHA1&';
  11.         $oauth_hash .= 'oauth_timestamp=' . time() . '&';
  12.         $oauth_hash .= 'oauth_token=' . $ACCESS_TOKEN . '&';
  13.         $oauth_hash .= 'oauth_version=1.0';
  14.         $base = '';
  15.         $base .= 'GET';
  16.         $base .= '&';
  17.         $base .= rawurlencode('https://api.twitter.com/1.1/statuses/user_timeline.json');
  18.         $base .= '&';
  19.         $base .= rawurlencode($oauth_hash);
  20.         $key = '';
  21.         $key .= rawurlencode($CONSUMER_SECRET);
  22.         $key .= '&';
  23.         $key .= rawurlencode($ACCESS_TOKEN_SECRET);
  24.         $signature = base64_encode(hash_hmac('sha1', $base, $key, true));
  25.         $signature = rawurlencode($signature);
  26.  
  27.         $oauth_header = '';
  28.         $oauth_header .= 'oauth_consumer_key="' . $CONSUMER_KEY . '", ';
  29.         $oauth_header .= 'oauth_nonce="' . time() . '", ';
  30.         $oauth_header .= 'oauth_signature="' . $signature . '", ';
  31.         $oauth_header .= 'oauth_signature_method="HMAC-SHA1", ';
  32.         $oauth_header .= 'oauth_timestamp="' . time() . '", ';
  33.         $oauth_header .= 'oauth_token="' . $ACCESS_TOKEN . '", ';
  34.         $oauth_header .= 'oauth_version="1.0", ';
  35.         $curl_header = array("Authorization: Oauth {$oauth_header}", 'Expect:');
  36.  
  37.         $curl_request = curl_init();
  38.         curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
  39.         curl_setopt($curl_request, CURLOPT_HEADER, false);
  40.         curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.json');
  41.         curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
  42.         curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
  43.         $json = curl_exec($curl_request);
  44.         curl_close($curl_request);
  45.  
  46.         return $json;
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement