I have no problem with ‘statuses/sample’ but I tried with ‘statuses/filter’ then I got Unauthorized error.
My code is below.Is there any mistake?
If anyone have ideas for this problem, I’d appreciate it. thanks!
$url = 'https://stream.twitter.com/1.1/statuses/filter.json';
$method = 'GET';
$additional_params = array(
'track' => 'Foo',
);
$oauth_params = array(
'oauth_consumer_key' => CONSUMER_KEY,
'oauth_nonce' => microtime(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => time(),
'oauth_token' => ACCESS_TOKEN,
'oauth_version' => '1.0a',
);
$base = $oauth_params;
$key = array(CONSUMER_SECRET, ACCESS_TOKEN_SECRET);
uksort($base, 'strnatcmp');
$oauth_params['oauth_signature'] = base64_encode(hash_hmac(
'sha1',
implode('&', array_map('rawurlencode', [
'GET',
$url,
http_build_query($base, '', '&', PHP_QUERY_RFC3986)
])),
implode('&', array_map('rawurlencode', $key)),
true
));
foreach ($oauth_params as $name => $value) {
$items[] = sprintf('%s="%s"', urlencode($name), urlencode($value));
}
$header = 'Authorization: OAuth ' . implode(', ', $items);
var_dump($header);
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url . '?' . http_build_query($additional_params, '', '&'),
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HTTPHEADER => array($header),
CURLOPT_ENCODING => 'gzip',
CURLOPT_TIMEOUT => 0,
));
curl_exec($ch);`