I use the following code to make a request to display a list of latest tweets on a website for a client:
if (file_exists( 'twitter.json' ))
{
$file = file_get_contents( 'twitter.json');
$data = json_decode($file);
if ($data->timestamp > (time() - 60 * 60) ) // if timestamp is NOT older than an hour
{
$twitter_result = $data->twitter_result;
}
else
{
$twitter_result = file_get_contents('http://api.twitter.com/1/statuses/user_timeline.json?q=@Twitter&rpp=1&screen_name=Twitter&count=1');
if( $twitter_result === false) /* something went wrong with API request */
{
$twitter_result = $data->twitter_result;
}
else
{
$json = array ('twitter_result' => $twitter_result, 'timestamp' => time());
file_put_contents( 'twitter.json', json_encode($json) );
}
}
header("content-type:application/json");
if($_GET['callback'])
{
echo $_GET['callback'] . '(' . $twitter_result . ')';
}
else
{
echo $twitter_result;
}
exit;
}
else
{
echo 'twitter.json does not exist!';
exit;
}
However due to the 1.0 API being depreciated it will no longer work! I have tried getting it to work with the 1.1 API but I don't understand how to implement the authentication like it says in the docs. Can anyone point me in the right direction? I'm looking to make the least amount of changes to the above code if possible. Thanks.
I've tried for example:
https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=twitterapi&count=2&oauth_token=123&oauth_token_secret=123
Where 123 are the token and secret but this also doesn't work?