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

Method obtain_access_token

twython/api.py:406–430  ·  view source on GitHub ↗

Returns an OAuth 2 access token to make OAuth 2 authenticated read-only calls. :rtype: string

(self)

Source from the content-addressed store, hash-verified

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
408 read-only calls.
409
410 :rtype: string
411 """
412 if self.oauth_version != 2:
413 raise TwythonError('This method can only be called when your \
414 OAuth version is 2.0.')
415
416 data = {'grant_type': 'client_credentials'}
417 basic_auth = HTTPBasicAuth(self.app_key, self.app_secret)
418 try:
419 response = self.client.post(self.request_token_url,
420 data=data, auth=basic_auth)
421 content = response.content.decode('utf-8')
422 try:
423 content = content.json()
424 except AttributeError:
425 content = json.loads(content)
426 access_token = content['access_token']
427 except (KeyError, ValueError, requests.exceptions.RequestException):
428 raise TwythonAuthError('Unable to obtain OAuth 2 access token.')
429 else:
430 return access_token
431
432 @staticmethod
433 def construct_api_url(api_url, **params):

Callers 1

Calls 3

TwythonErrorClass · 0.85
TwythonAuthErrorClass · 0.85
postMethod · 0.80

Tested by 1