Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate limit exceeded #94

Open
AnonDev1312 opened this issue Mar 9, 2018 · 1 comment
Open

Rate limit exceeded #94

AnonDev1312 opened this issue Mar 9, 2018 · 1 comment

Comments

@AnonDev1312
Copy link

AnonDev1312 commented Mar 9, 2018

I'm just trying to write a small script to unfollow the users not following back

is there limit of requests per minute on top of the hourly limits? I'm trying to make a simple automation app to unfollow the users not following back. I have around 6k followers and I'm following 2.2k so assuming 20 results per requests, I shouldn't be hitting the 1000 hourly limit (should be around 410 requests)

The API is returning error "Limit Exceeded" however when I check the headers it still shows I have requests left before hitting the limits

object(Tumblr\API\RequestException)#29 (8) { ["message":protected]=> string(14) "Limit Exceeded" ["string":"Exception":private]=> string(0) "" ["code":protected]=> int(429) ["file":protected]=> string(89) "/home/libertaire/public_html/test/composer/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php" ["line":protected]=> int(427) ["trace":"Exception":private]=> array(3) { [0]=> array(6) { ["file"]=> string(89) "/home/libertaire/public_html/test/composer/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php" ["line"]=> int(387) ["function"]=> string(13) "parseResponse" ["class"]=> string(17) "Tumblr\API\Client" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> object(stdClass)#30 (4) { ["status"]=> int(429) ["body"]=> string(89) "{"meta":{"status":429,"msg":"Limit Exceeded"},"response":{"error":"Rate Limit Exceeded"}}" ["headers"]=> array(18) { ["Server"]=> array(1) { [0]=> string(3) "ATS" } ["Date"]=> array(1) { [0]=> string(29) "Fri, 09 Mar 2018 05:31:07 GMT" } ["Content-Type"]=> array(1) { [0]=> string(31) "application/json; charset=utf-8" } ["X-Rid"]=> array(1) { [0]=> string(13) "copcpr9da470r" } ["Strict-Transport-Security"]=> array(1) { [0]=> string(16) "max-age=15552000" } ["X-Ratelimit-Perday-Limit"]=> array(1) { [0]=> string(4) "5000" } ["X-Ratelimit-Perday-Remaining"]=> array(1) { [0]=> string(4) "3292" } ["X-Ratelimit-Perday-Reset"]=> array(1) { [0]=> string(5) "58373" } ["X-Ratelimit-Perhour-Limit"]=> array(1) { [0]=> string(4) "1000" } ["X-Ratelimit-Perhour-Remaining"]=> array(1) { [0]=> string(3) "930" } ["X-Ratelimit-Perhour-Reset"]=> array(1) { [0]=> string(4) "3591" } ["P3p"]=> array(1) { [0]=> string(88) "CP="Tumblr's privacy policy is available here: https://www.tumblr.com/policy/en/privacy"" } ["Age"]=> array(1) { [0]=> string(1) "0" } ["Transfer-Encoding"]=> array(1) { [0]=> string(7) "chunked" } ["Connection"]=> array(1) { [0]=> string(10) "keep-alive" } ["Via"]=> array(1) { [0]=> string(63) "https/1.1 e15.ycpi.dca.yahoo.com (ApacheTrafficServer [cMsSf ])" } ["Expect-CT"]=> array(1) { [0]=> string(97) "max-age=31536000, report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-expect-ct-report-only"" } ["Public-Key-Pins-Report-Only"]=> array(1) { [0]=> string(1054) "max-age=2592000; pin-sha256="2fRAUXyxl4A1/XHrKNBmc8bTkzA7y4FB/GLJuNAzCqY="; pin-sha256="2oALgLKofTmeZvoZ1y/fSZg7R9jPMix8eVA6DH4o/q8="; pin-sha256="Gtk3r1evlBrs0hG3fm3VoM19daHexDWP//OCmeeMr5M="; pin-sha256="I/Lt/z7ekCWanjD0Cvj5EqXls2lOaThEA0H2Bg4BT/o="; pin-sha256="JbQbUG5JMJUoI6brnx0x3vZF6jilxsapbXGVfjhN8Fg="; pin-sha256="SVqWumuteCQHvVIaALrOZXuzVVVeS7f4FGxxu6V+es4="; pin-sha256="UZJDjsNp1+4M5x9cbbdflB779y5YRBcV6Z6rBMLIrO4="; pin-sha256="Wd8xe/qfTwq3ylFNd3IpaqLHZbh2ZNCLluVzmeNkcpw="; pin-sha256="WoiWRyIOVNa9ihaBciRSC7XHjliYS9VwUGOIud4PB18="; pin-sha256="cAajgxHlj7GTSEIzIYIQxmEloOSoJq7VOaxWHfv72QM="; pin-sha256="dolnbtzEBnELx/9lOEQ22e6OZO/QNb6VSSX2XHA3E7A="; pin-sha256="i7WTqTvh0OioIruIfFR4kMPnBqrS2rdiVPl/s2uC/CY="; pin-sha256="iduNzFNKpwYZ3se/XV+hXcbUonlLw09QPa6AYUwpu4M="; pin-sha256="lnsM2T/O9/J84sJFdnrpsFp3awZJ+ZZbYpCWhGloaHI="; pin-sha256="r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="; pin-sha256="uUwZgwDOxcBXrQcntwu+kYFpkiVkOaezL0WYEZ3anJc="; includeSubdomains; report-uri="http://csp.yahoo.com/beacon/csp?src=yahoocom-hpkp-report-only"" } } ["json"]=> object(stdClass)#65 (2) { ["meta"]=> object(stdClass)#22 (2) { ["status"]=> int(429) ["msg"]=> string(14) "Limit Exceeded" } ["response"]=> object(stdClass)#20 (1) { ["error"]=> string(19) "Rate Limit Exceeded" } } } } } [1]=> array(6) { ["file"]=> string(89) "/home/libertaire/public_html/test/composer/vendor/tumblr/tumblr/lib/Tumblr/API/Client.php" ["line"]=> int(93) ["function"]=> string(10) "getRequest" ["class"]=> string(17) "Tumblr\API\Client" ["type"]=> string(2) "->" ["args"]=> array(3) { [0]=> string(17) "v2/user/following" [1]=> array(1) { ["offset"]=> int(1340) } [2]=> bool(false) } } [2]=> array(6) { ["file"]=> string(62) "/home/libertaire/public_html/test/unfollowNonFollowersTest.php" ["line"]=> int(36) ["function"]=> string(16) "getFollowedBlogs" ["class"]=> string(17) "Tumblr\API\Client" ["type"]=> string(2) "->" ["args"]=> array(1) { [0]=> array(1) { ["offset"]=> int(1340) } } } } ["previous":"Exception":private]=> NULL ["statusCode"]=> int(429) }

Here's my code

$client = new Tumblr\API\Client(
    'pICR56D1IzU8rdjaJ18ba8GUGMGiVcx3a3wk4VerhTYjZXd***',
    'f2AVQAzNvGAJMEhJwn4X4B6ny22rKo1hFOTzSBFU28IepDm***',
    'n2q0RnJpsnBXHU0qwNVRU6XyuL6e4tRXNjOuipvpgMW6WGt***',
    '7D2kZPge37lC7HsWS0qpKOoY3szYDoxtgXDMP5AM0mA1Wn6***'
  );

  $my_blog = "***.tumblr.com";
  $blog_followers = $client->getBlogFollowers($my_blog)->total_users;
  $blog_followings = $client->getFollowedBlogs()->total_blogs;
  $i = 0;

  try {
// ******************************
// GET FOLLOWINGS LIST

$array_following = array();
while ($i <= $blog_followings) {
    $get_followings = $client->getFollowedBlogs(array('offset' => $i));

    foreach($get_followings->blogs as $following) {
      $array_following[] = $following->url;
    }
    $i = $i + 20;
}

echo "<h1>array_following</h1>";
print_r($array_following);



// ******************************
// GET FOLLOWERS LIST

$array_followers = array();
$i = 0;
while ($i <= $blog_followers) {
  $get_followers = $client->getBlogFollowers("$my_blog", array('offset' => $i));
    foreach($get_followers->users as $follower) {
    $array_followers[] = $follower->url;
    }
  $i = $i + 20;
}

echo "<h1>array_followers</h1>";
print_r($array_followers);



// ******************************
// ERROR HANDLING - RATE LIMITING

} catch (Exception $e) {
  echo "<h1 style='color:#ff0000'>ERROR ". $e->getMessage() ."</h1>";
  var_dump($e);
}
@mystiquewolf
Copy link

300 API calls per minute -> https://www.tumblr.com/docs/en/api/v2#rate-limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants