-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Twitter error checks #2416
Conversation
…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.
$code = $this->get_return_code($e); | ||
if ($code == 503) { | ||
header('Retry-After: 600', true); | ||
} | ||
header('Content-Type: text/html', true, $code); |
There was a problem hiding this comment.
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)?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
…s to reuse old guesttokens until a new one was successfully aquired.
…/rss-bridge into twitter_error_checks
Change double quotes to singles to satisfy phpcs
arnd-s is rewriting the twitter bridge because of a issue #2432 so cancel this |
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.