Skip to content

Instantly share code, notes, and snippets.

@cosmocatalano
Last active December 16, 2015 04:33
Show Gist options
  • Save cosmocatalano/4444203 to your computer and use it in GitHub Desktop.
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.
<?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)';
?>
@lmj0011
Copy link

lmj0011 commented Dec 16, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment