$url = "https://api.twitter.com/1.1/search/tweets.json?q=xyz";
$oauth_access_token = "xxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$oauth_access_token_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxx";
$consumer_key = "xxxxxxxxxxxxxxxxxxxxxxxx";
$consumer_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$oauth = array('oauth_consumer_key' => $consumer_key,
'oauth_nonce' => time(),
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_token' => $oauth_access_token,
'oauth_timestamp' => time(),
'oauth_version' => '1.1');
$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;
$header = array($this->buildAuthorizationHeader($oauth), 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$feed = curl_init();
curl_setopt_array($feed, $options);
echo $json = curl_exec($feed);
curl_close($feed);
$twitter_data = json_decode($json);
しかし、「Bad Authentication data」というエラーが表示されます