#NEWLINE# def obtain_access_token( self ) : #NEWLINE# #INDENT# 'Returns an OAuth 2 access token to make OAuth 2 authenticated read-only calls.\n\n        :rtype: string\n        ' #NEWLINE# if ( self . oauth_version != 2 ) : #NEWLINE# #INDENT# raise TwythonError ( 'This method can only be called when your OAuth version is 2.0.' ) #NEWLINE# #UNINDENT# data = { #NEWLINE# #INDENT# 'grant_type' : 'client_credentials' , #NEWLINE# #UNINDENT# } #NEWLINE# basic_auth = HTTPBasicAuth ( self . app_key , self . app_secret ) #NEWLINE# try : #NEWLINE# #INDENT# response = self . client . post ( self . request_token_url , data = data , auth = basic_auth ) #NEWLINE# content = response . content . decode ( 'utf-8' ) #NEWLINE# try : #NEWLINE# #INDENT# content = content . json ( ) #NEWLINE# #UNINDENT# except AttributeError : #NEWLINE# #INDENT# content = json . loads ( content ) #NEWLINE# access_token = content [ 'access_token' ] #NEWLINE# #UNINDENT# #UNINDENT# except ( ValueError , requests . exceptions . RequestException ) : #NEWLINE# #INDENT# raise TwythonAuthError ( 'Unable to obtain OAuth 2 access token.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return access_token