PHP/User timeline code not working


#1

Below is copy/paste PHP code which for some reason is failing to return me any user timeline data and I cannot see for the life of me why. Please can someone advise. Thanks

define('CONSUMER_KEY', '');
define('CONSUMER_SECRET', '');
define('OAUTH_TOKEN','');
define('OAUTH_SECRET','');
define('USER_ID','');

function generateSignature($oauth,$fullurl,$http_method){        

// Take params from url
$main_url = explode('?',$fullurl);        

$urls = explode('&',$main_url[1]);

foreach ($urls as $param){
$bits = explode('=',$param);
if (strlen($bits[0])){
$oauth[$bits[0]] = rawurlencode($bits[1]);
}    
}

ksort($oauth);

$string = http_build_query($oauth);

$new_string = strtoupper($http_method).'&'.urlencode($main_url[0]).'&'.urlencode(urldecode($string));           

$sign_str = CONSUMER_SECRET.'&'.OAUTH_SECRET;

return urlencode(base64_encode(hash_hmac('sha1',$new_string,$sign_str,true)));        
} 

function random($len,$use_chars = false,$numU = false){
$num = range(0,9);
$letu = range('A','Z');
$letl = range('a','z');
$chars = array("!","*","£","$","^","(",")","_","+");

if ($use_chars){
$arr = array_merge($num,$letu,$letl,$chars);
} else {
$arr = array_merge($num,$letu,$letl);
}

// Shuffling - new addition 11/9 to make order actually random!
shuffle($arr);

// Create a number only random string
if ($numU){ $arr = $num; }

$rand = array_rand($arr,$len);
foreach ($rand as $num){
$out[] = $arr[$num];
}

return implode('',$out);
}

$method = 'GET';

// Twitter still uses Oauth1 (which is a pain)
$oauth = array(
'oauth_consumer_key'=>CONSUMER_KEY,
'oauth_nonce'=>random(32),
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_timestamp'=>time(),
'oauth_token'=>OAUTH_TOKEN,
'oauth_version'=>'1.0',
);                    

$url = "https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=".USER_ID;

$oauth['oauth_signature'] = generateSignature($oauth,$url,$method,'');                                

ksort($oauth);

foreach ($oauth as $k=>$v){
$auths[] = $k.'="'.$v.'"';
}

$stream = array('http' =>
array(
'method' => $method,
// ignore_errors should be true
'ignore_errors'=>true, // http://php.net/manual/en/context.http.php - otherwise browser returns error not error content
'follow_location'=>false,
'max_redirects'=>0,
'header'=> array(
'Authorization: OAuth '.implode(', ',$auths),
'Connection: close'
)                                             
)
);                                                                                                                 

echo $url;                                                 
$response = file_get_contents($url, false, stream_context_create($stream));

print'<pre>';print_r($stream);print'</pre>';
print'<pre>[';print_r($reponse);print']</pre>';