g-trends icon indicating copy to clipboard operation
g-trends copied to clipboard

How to avoid HTTP status 429 (too many requests)?

Open Rombersoft opened this issue 3 years ago • 5 comments

Who can share experiences about problems with HttpStatus 429 (Too many requests)? I noticed that the developer thought about using the proxy server. Does it exist some statistics about what I must do in order to be banned by Google Corporation? Public API is missing and how much is legal to use google back end in order to show google trends results on my own site???

Rombersoft avatar Oct 14 '22 21:10 Rombersoft

change lines: 141 to: throw new \Exception('Maximum five keywords accepted. Split and loop, if more'); // optional 276 to: throw new \Exception($client->getResponse()->getReasonPhrase().' / '.$client->getResponse()->getStatusCode());

then use sleep($delay) with loop increasing sleep time $delay e.g. by 5s each time, when exception is thrown until you get the trend results.

example:

$result = [];
$sleep = 0;
while ($result == []) {
    try {
        $result = $gt->getInterestOverTime($keyword_group);
    } catch (\Exception $e) {
        $sleep = $sleep + 5;
    }
    sleep($sleep);
}

nekromoff avatar Apr 27 '23 14:04 nekromoff