Skip to content

Commit

Permalink
Related to twintproject#1320
Browse files Browse the repository at this point in the history
Reference: twintproject#1328, twintproject#1322

This problem doesn't happen recently, but too big is better than too small.
  • Loading branch information
minamotorin committed Feb 6, 2022
1 parent e7c8a0c commit 3eeed65
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions twint/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,30 @@ def refresh(self):
logme.debug('Found guest token in HTML')
self.config.Guest_token = str(match.group(1))
else:
self.config.Guest_token = None
raise RefreshTokenException('Could not find the Guest token in HTML')
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
'authority': 'api.twitter.com',
'content-length': '0',
'authorization': self.config.Bearer_token,
'x-twitter-client-language': 'en',
'x-csrf-token': res.cookies.get("ct0"),
'x-twitter-active-user': 'yes',
'content-type': 'application/x-www-form-urlencoded',
'accept': '*/*',
'sec-gpc': '1',
'origin': 'https://twitter.com',
'sec-fetch-site': 'same-site',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://twitter.com/',
'accept-language': 'en-US',
}
self._session.headers.update(headers)
req = self._session.prepare_request(requests.Request('POST', 'https://api.twitter.com/1.1/guest/activate.json'))
res = self._session.send(req, allow_redirects=True, timeout=self._timeout)
if 'guest_token' in res.json():
logme.debug('Found guest token in JSON')
self.config.Guest_token = res.json()['guest_token']
else:
self.config.Guest_token = None
raise RefreshTokenException('Could not find the Guest token in HTML')

0 comments on commit 3eeed65

Please sign in to comment.