Last active
December 15, 2015 06:19
-
-
Save jongacnik/5215416 to your computer and use it in GitHub Desktop.
Little snippet to grab tweets and store the json at maximum once an hour to avoid going over api limits. Does all this without cron so we use the log file to keep track of the last grab and the tweets.json stores the tweets for us.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$handle = 'handle'; | |
$count = 24; | |
$url = 'http://api.twitter.com/1/statuses/user_timeline/'.$handle.'.json?count='.$count; | |
$lastGrabLog = './lastGrab.log'; | |
$twitGit = './tweets.json'; | |
$interval = 3600; | |
if (file_exists($lastGrabLog)) { | |
$lastGrab = file_get_contents($lastGrabLog); | |
if (time() - $lastGrab >= $interval) { | |
$tweets = file_get_contents($url); | |
file_put_contents($twitGit, $tweets); | |
file_put_contents($lastGrabLog, time()); | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0000000000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ "tweet":"tweet" } | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment