Skip to content

Instantly share code, notes, and snippets.

@mrl22
Last active December 16, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mrl22/f41b008525c92d321c382d0b287b6d6e to your computer and use it in GitHub Desktop.
Save mrl22/f41b008525c92d321c382d0b287b6d6e to your computer and use it in GitHub Desktop.
<?php
// Dont forget to load twitter oauth via Composer
$twitteruser = 'webfwd';
$tweetexpire = 60 * 30; // Seconds
$tweetfile = '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