Skip to content

Instantly share code, notes, and snippets.

@brendonexus
Forked from mrl22/latest-tweet.php
Created December 6, 2016 16:59
Show Gist options
  • Save brendonexus/d79f42ee3f3bbe0eb5ec8c0e03dab16a to your computer and use it in GitHub Desktop.
Save brendonexus/d79f42ee3f3bbe0eb5ec8c0e03dab16a to your computer and use it in GitHub Desktop.
<?php
require '_config.php';
$twitteruser = 'webfwd';
$tweetexpire = 60 * 30; // Seconds
$tweetfile = DOCROOT.'/twitter.txt';
use Abraham\TwitterOAuth\TwitterOAuth;
if (!file_exists($tweetfile) || (time()-filemtime($tweetfile)) > $tweetexpire) {
$connection = new TwitterOAuth(
"", // API Key
"", // API Secret
"", // Access Token
"" // Access Token Secret
);
$content = $connection->get("account/verify_credentials");
$statuses = $connection->get('statuses/user_timeline', array('screen_name' => $twitteruser, 'exclude_replies' => 'true', 'include_rts' => 'false', 'count' => 1));
$tweet = $statuses[0]->text;
file_put_contents($tweetfile, $tweet);
} else $tweet = file_get_contents($tweetfile);
echo $tweet;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment