#NEWLINE# def add_access_token( creds_file = None ) : #NEWLINE# #INDENT# '\n    For OAuth 2, retrieve an access token for an app and append it to a\n    credentials file.\n    ' #NEWLINE# if ( creds_file is None ) : #NEWLINE# #INDENT# path = os . path . dirname ( __file__ ) #NEWLINE# creds_file = os . path . join ( path , 'credentials2.txt' ) #NEWLINE# #UNINDENT# oauth2 = credsfromfile ( creds_file = creds_file ) #NEWLINE# app_key = oauth2 [ 'app_key' ] #NEWLINE# app_secret = oauth2 [ 'app_secret' ] #NEWLINE# twitter = Twython ( app_key , app_secret , oauth_version = 2 ) #NEWLINE# access_token = twitter . obtain_access_token ( ) #NEWLINE# tok = 'access_token={}\n' . format ( access_token ) #NEWLINE# with open ( creds_file , 'a' ) as infile : #NEWLINE# #INDENT# print ( tok , file = infile )