Last active
December 16, 2015 04:33
-
-
Save cosmocatalano/4444203 to your computer and use it in GitHub Desktop.
A short script to check in with Twitter and see how many more unauthenticated requests you can make to their API. Handy for shared hosting accounts, especially if your host is GoDaddy.
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 | |
function api_pull($url) { | |
$API_object = file_get_contents($url); | |
$array = json_decode($API_object, TRUE); | |
return $array; | |
} | |
$now = time(); | |
$reply = api_pull('https://api.twitter.com/1/account/rate_limit_status.json'); | |
echo 'Your IP address has '.$reply['remaining_hits'];.' calls to Twitter remaining'; | |
echo '</br>The counter resets in '.round(($reply['reset_time_in_seconds'] - $now)/60).' minute(s)'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A good counter to api request limits would be to save the data you're requesting to a database on your webhost and then have clients pull it from there. Just have the database refresh itself at an interval that doesn't go beyond your request limit. This is ideal, if you don't need real time data requesting.