code: def get_credentials(credentials=None, client_secret_file=CLIENT_SECRET_FILE, refresh_token=None):
      
  
      # if the utility was provided credentials just return those
      if credentials:
          if _is_valid_credentials(credentials):
              # auth for gspread
              return credentials
          else:
              print("Invalid credentials supplied. Will generate from default token.")
  
      token = refresh_token or DEFAULT_TOKEN
      dir_name = os.path.dirname(DEFAULT_TOKEN)
      try:
          os.makedirs(dir_name)
      except OSError:
          if not os.path.isdir(dir_name):
              raise
      store = file.Storage(token)
      credentials = store.get()
  
      try:
          import argparse
          flags = argparse.ArgumentParser(
              parents=[tools.argparser]).parse_known_args()[0]
      except ImportError:
          flags = None
          logr.error(
              'Unable to parse oauth2client args; `pip install argparse`')
  
      if not credentials or credentials.invalid:
  
          flow = client.flow_from_clientsecrets(
              client_secret_file, SCOPES)
          flow.redirect_uri = client.OOB_CALLBACK_URN
          if flags:
              credentials = tools.run_flow(flow, store, flags)
          else:  # Needed only for compatability with Python 2.6
              credentials = tools.run(flow, store)
          logr.info('Storing credentials to ' + DEFAULT_TOKEN)
  
      return credentials
docs: Consistently returns valid credentials object.
  
      See Also:
          https://developers.google.com/drive/web/quickstart/python
  
      Args:
          client_secret_file (str): path to client secrets file, defaults to .gdrive_private
          refresh_token (str): path to a user provided refresh token that is already
              pre-authenticated
          credentials (`~oauth2client.client.OAuth2Credentials`, optional): handle direct
              input of credentials, which will check credentials for valid type and
              return them
  
      Returns:
          `~oauth2client.client.OAuth2Credentials`: google credentials object