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

Twitter error checks #2416

Conversation

berenddeschouwer
Copy link

This builds on PR #2414 by arnd-s

Sometimes twitter invalidates our API key and/or guest token before expiry, and we need to delete the token we have and try again.

When this happens Twitter will return 403. Treat the first occurrence of 403 as EAGAIN. Do not retry infinitely.

arnd-s and others added 3 commits January 7, 2022 16:27
…sting new guest tokens

Instead of searching inside base html page for the guest token, this patch instead uses the Twitter REST API V1.1 to aquire the nessecary guest tokens.
Allow setting error 503 (temporary failure) and set a retry
header for clients that understand 503
Sometimes our cached guest token or API key is no longer valid,
and Twitter returns 403.  When this happens attempt
to re-get an API key and get the contents.

After API_RETRIES times, give up and return an error.
Comment on lines +227 to +231
$code = $this->get_return_code($e);
if ($code == 503) {
header('Retry-After: 600', true);
}
header('Content-Type: text/html', true, $code);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain, why do we need it here? And why 600 (10 minutes)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to tell the RSS reader that the error is temporary.

All the Twitter 403 errors I've received over the last few weeks have been temporary, so I wanted a way to tell the RSS reader to try again soon. I don't know if any readers treat 500 different from 503.

The 10 minutes is just a guess.

@@ -481,7 +482,7 @@ private static function compareTweetId($tweet1, $tweet2) {

//The aim of this function is to get an API key and a guest token
//This function takes 2 requests, and therefore is cached
private function getApiKey() {
private function getApiKey($dumpToken) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of dumpToken? Flag to ignore cache with api key and guest token?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is to invalidate the cached guest token.

I could also delete the token before calling getApiKey() the second time in getApiContents(), and not pass a flag.

arnd-s and others added 3 commits January 10, 2022 09:35
…s to reuse old guesttokens until a new one was successfully aquired.
Change double quotes to singles to satisfy phpcs
@berenddeschouwer
Copy link
Author

arnd-s is rewriting the twitter bridge because of a issue #2432 so cancel this

@berenddeschouwer berenddeschouwer deleted the twitter_error_checks branch January 22, 2022 06:52
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

Successfully merging this pull request may close these issues.

4 participants