From e1be79a45becd708bae61c2b1f173059b8921f48 Mon Sep 17 00:00:00 2001 From: arnds Date: Thu, 30 Dec 2021 20:20:33 +0100 Subject: [PATCH 1/2] [TwitterBridge] Continue using existing guesttoken from cache, when requesting a new one failed. --- bridges/TwitterBridge.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index e54a5d02681..6fbbee20e6a 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -546,8 +546,16 @@ private function getApiKey() { if($guestTokenUses === null || !is_array($guestTokenUses) || count($guestTokenUses) != 2 || $guestTokenUses[0] <= 0 || (time() - $refresh) > self::GUEST_TOKEN_EXPIRY) { $guestToken = $this->getGuestToken(); - $gt_cache->saveData(array(self::GUEST_TOKEN_USES, $guestToken)); - $r_cache->saveData(time()); + if ($guestToken === null) { + if($guestTokenUses === null) { + returnServerError('Could not parse guest token'); + } else { + $guestToken = $guestTokenUses[1]; + } + } else { + $gt_cache->saveData(array(self::GUEST_TOKEN_USES, $guestToken)); + $r_cache->saveData(time()); + } } else { $guestTokenUses[0] -= 1; $gt_cache->saveData($guestTokenUses); From 42d541463ca0d84c6ad34eedb33f138b08030edd Mon Sep 17 00:00:00 2001 From: arnds Date: Fri, 31 Dec 2021 08:17:00 +0100 Subject: [PATCH 2/2] [TwitterBridge] return null instead of rising a exception so that already existing guesttoken from cache can be reused --- bridges/TwitterBridge.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php index 6fbbee20e6a..a14e5062221 100644 --- a/bridges/TwitterBridge.php +++ b/bridges/TwitterBridge.php @@ -575,7 +575,7 @@ private function getGuestToken() { preg_match_all($guestTokenRegex, $pageContent['header'], $guestTokenMatches, PREG_SET_ORDER, 0); if (!$guestTokenMatches) preg_match_all($guestTokenRegex, $pageContent['content'], $guestTokenMatches, PREG_SET_ORDER, 0); - if (!$guestTokenMatches) returnServerError('Could not parse guest token'); + if (!$guestTokenMatches) return null; $guestToken = $guestTokenMatches[0][1]; return $guestToken; }