Search API keeps giving me: "Could not authenticate you"


#1

I keep getting the error that twitter could not authenticate me.

Though my API keys and tokens are set properly.

What am I doing wrong here?

<?php

	$oauth_hash = '';
	$oauth_hash .= 'oauth_consumer_key=*****************&';
	$oauth_hash .= 'oauth_nonce=' . time() . '*****************&';
	$oauth_hash .= 'oauth_signature_method=HMAC-SHA1&';
	$oauth_hash .= 'oauth_timestamp=' . time() . '&';
	$oauth_hash .= 'oauth_token=*****************&';
	$oauth_hash .= 'oauth_version=1.0&';
	$oauth_hash .= 'q=ICT+ITPH&';
	$oauth_hash .= 'result_type=mixed';

	$base = '';
	$base .= 'GET';
	$base .= '&';
	$base .= rawurlencode('https://api.twitter.com/1.1/search/tweets.json');
	$base .= '&';
	$base .= rawurlencode($oauth_hash);
	$key = '';
	$key .= rawurlencode('*****************');
	$key .= '&';
	$key .= rawurlencode('*****************');
	$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
	$signature = rawurlencode($signature);


	$oauth_header = '';
	$oauth_header .= 'oauth_consumer_key="*****************", ';
	$oauth_header .= 'oauth_nonce="' . time() . '*****************", ';
	$oauth_header .= 'oauth_signature="' . $signature . '", ';
	$oauth_header .= 'oauth_signature_method="HMAC-SHA1", ';
	$oauth_header .= 'oauth_timestamp="' . time() . '", ';
	$oauth_header .= 'oauth_token="*****************", ';
	$oauth_header .= 'oauth_version="1.0", ';
	$curl_header = array("Authorization: OAuth {$oauth_header}", 'Expect:');
	
	$curl_request = curl_init();
	curl_setopt($curl_request, CURLOPT_HTTPHEADER, $curl_header);
	curl_setopt($curl_request, CURLOPT_HEADER, false);
	curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/search/tweets.json');
	curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
	$json = curl_exec($curl_request);
	curl_close($curl_request);

	var_dump($json);

	foreach($json as $tweet)
	{
	  echo "<div class='twitter_feed'>{$tweet->text} {$tweet->created_at}</div>\n";
	}

	print_r($curl_header);

?>