def get_account_id(service):
  """Gets the AdSense account id, letting the user choose if multiple exist.

  Args:
    service: the Adsense service used to fetch the accounts.

  Returns:
    The selected account id.
  """
  account_id = None
  response = service.accounts().list().execute()
  if len(response['accounts']) == 1:
    account_id = response['accounts'][0]['name']
  else:
    print('Multiple accounts were found. Please choose:')
    for i, account in enumerate(response['accounts']):
      print(' %d) %s (%s)' % (i + 1, account['displayName'], account['name']))
    selection = (input('Please choose number 1-%d>'
                           % (len(response['accounts']))))
    account_id = response['accounts'][int(selection) - 1]['name']
  return account_id