MCPcopy Index your code
hub / github.com/ryanmcgrath/twython / get_authorized_tokens

Method get_authorized_tokens

twython/api.py:368–404  ·  view source on GitHub ↗

Returns a dict of authorized tokens after they go through the :class:`get_authentication_tokens` phase. :param oauth_verifier: (required) The oauth_verifier (or a.k.a PIN for non web apps) retrieved from the callback url querystring :rtype: dict

(self, oauth_verifier)

Source from the content-addressed store, hash-verified

366 return request_tokens
367
368 def get_authorized_tokens(self, oauth_verifier):
369 """Returns a dict of authorized tokens after they go through the
370 :class:`get_authentication_tokens` phase.
371
372 :param oauth_verifier: (required) The oauth_verifier (or a.k.a PIN
373 for non web apps) retrieved from the callback url querystring
374 :rtype: dict
375
376 """
377 if self.oauth_version != 1:
378 raise TwythonError('This method can only be called when your \
379 OAuth version is 1.0.')
380
381 response = self.client.get(self.access_token_url,
382 params={'oauth_verifier': oauth_verifier},
383 headers={'Content-Type': 'application/\
384 json'})
385
386 if response.status_code == 401:
387 try:
388 try:
389 # try to get json
390 content = response.json()
391 except AttributeError: # pragma: no cover
392 # if unicode detected
393 content = json.loads(response.content)
394 except ValueError:
395 content = {}
396
397 raise TwythonError(content.get('error', 'Invalid / expired To \
398 ken'), error_code=response.status_code)
399
400 authorized_tokens = dict(parse_qsl(response.content.decode('utf-8')))
401 if not authorized_tokens:
402 raise TwythonError('Unable to decode authorized tokens.')
403
404 return authorized_tokens # pragma: no cover
405
406 def obtain_access_token(self):
407 """Returns an OAuth 2 access token to make OAuth 2 authenticated

Callers

nothing calls this directly

Calls 2

TwythonErrorClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected