code: def ServiceAccountCredentialsFromFile(filename, scopes, user_agent=None):
      
      filename = os.path.expanduser(filename)
      # We have two options, based on our version of oauth2client.
      if oauth2client.__version__ > '1.5.2':
          # oauth2client >= 2.0.0
          credentials = (
              service_account.ServiceAccountCredentials.from_json_keyfile_name(
                  filename, scopes=scopes))
          if credentials is not None:
              if user_agent is not None:
                  credentials.user_agent = user_agent
          return credentials
      else:
          # oauth2client < 2.0.0
          with open(filename) as keyfile:
              service_account_info = json.load(keyfile)
          account_type = service_account_info.get('type')
          if account_type != oauth2client.client.SERVICE_ACCOUNT:
              raise exceptions.CredentialsError(
                  'Invalid service account credentials: %s' % (filename,))
          # pylint: disable=protected-access
          credentials = service_account._ServiceAccountCredentials(
              service_account_id=service_account_info['client_id'],
              service_account_email=service_account_info['client_email'],
              private_key_id=service_account_info['private_key_id'],
              private_key_pkcs8_text=service_account_info['private_key'],
              scopes=scopes, user_agent=user_agent)
          # pylint: enable=protected-access
          return credentials
docs: Use the credentials in filename to create a token for scopes.