Yesterday, I posted about Search for Mentions of a Topic with the Twitter API. I asked about what URL to use, since I thought I was doing it wrong.
As it turns out, my initial guess on which URL to use was correct (as it should have been, since I used Twitter Dev Console to get the URL. The problem seems to be in actually using the URL in the code I found. I have very limited understanding of the Twitter API, but it seems to be very difficult to do simple things now...
I'm trying to use this code (which I found in a blog post) to access tweets. When I load a PHP page with just this code (with my information in it, of course), I have no problem seeing tweets from my personal account (I DO have an application set up on my account, of course). But when I try to change the two URLs in the code itself, I get {"errors":[{"message":"Could not authenticate you","code":32}]}
. So how else do I need to modify the code?
Note: HERE is the original blog post I found the code for.
EDIT: Here is the code I'm using exactly (well, minus my info):
<?php
//After you create the app at http://dev.twitter.com, you'll need to get the following four pieces of data from the details tab in your app's page.
$consumer_key = '';
$consumer_secret = '';
$access_token = '';
$access_token_secret = '';
$oauth_hash = 'oauth_consumer_key='.$consumer_key.
'&oauth_nonce='.time().
'&oauth_signature_method=HMAC-SHA1&oauth_timestamp='.
time().'&oauth_token='.$access_token.'&oauth_version=1.0';
// $base = 'GET&'.rawurlencode('http://api.twitter.com/1.1/search/tweets.json?q=apple&result_type=recent&count=10').
// '&'.rawurlencode($oauth_hash);
$base = 'GET&'.rawurlencode('https://api.twitter.com/1.1/statuses/user_timeline.json').
'&'.rawurlencode($oauth_hash);
$key = rawurlencode($consumer_secret).'&'. rawurlencode($access_token_secret);
$signature = base64_encode(hash_hmac('sha1', $base, $key, true));
$signature = rawurlencode($signature);
$oauth_header = 'oauth_consumer_key="'.$consumer_key.'",
oauth_nonce="' . time() . '",oauth_signature="' . $signature . '",
oauth_signature_method="HMAC-SHA1",
oauth_timestamp="' . time() . '",
oauth_token='.$access_token.',
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, 'http://api.twitter.com/1.1/search/tweets.json?q=apple&result_type=recent&count=10');
curl_setopt($curl_request, CURLOPT_URL, 'https://api.twitter.com/1.1/statuses/user_timeline.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);
echo $json;