Skip to content

Commit 3eeed65

Browse files
authored
Related to twintproject#1320
Reference: twintproject#1328, twintproject#1322 This problem doesn't happen recently, but too big is better than too small.
1 parent e7c8a0c commit 3eeed65

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

twint/token.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,30 @@ def refresh(self):
6565
logme.debug('Found guest token in HTML')
6666
self.config.Guest_token = str(match.group(1))
6767
else:
68-
self.config.Guest_token = None
69-
raise RefreshTokenException('Could not find the Guest token in HTML')
68+
headers = {
69+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
70+
'authority': 'api.twitter.com',
71+
'content-length': '0',
72+
'authorization': self.config.Bearer_token,
73+
'x-twitter-client-language': 'en',
74+
'x-csrf-token': res.cookies.get("ct0"),
75+
'x-twitter-active-user': 'yes',
76+
'content-type': 'application/x-www-form-urlencoded',
77+
'accept': '*/*',
78+
'sec-gpc': '1',
79+
'origin': 'https://twitter.com',
80+
'sec-fetch-site': 'same-site',
81+
'sec-fetch-mode': 'cors',
82+
'sec-fetch-dest': 'empty',
83+
'referer': 'https://twitter.com/',
84+
'accept-language': 'en-US',
85+
}
86+
self._session.headers.update(headers)
87+
req = self._session.prepare_request(requests.Request('POST', 'https://api.twitter.com/1.1/guest/activate.json'))
88+
res = self._session.send(req, allow_redirects=True, timeout=self._timeout)
89+
if 'guest_token' in res.json():
90+
logme.debug('Found guest token in JSON')
91+
self.config.Guest_token = res.json()['guest_token']
92+
else:
93+
self.config.Guest_token = None
94+
raise RefreshTokenException('Could not find the Guest token in HTML')

0 commit comments

Comments
 (0)