帐号标签
    
    
      
    
    
      
      使用集合让一切井井有条
    
    
      
      根据您的偏好保存内容并对其进行分类。
    
  
    
  
      
    
  
  
  
  
  
    
    
    
  
  
    
    
    
创建一个账号标签
function createAccountLabels(labelName) {
  AdsManagerApp.createAccountLabel(labelName);
  console.log("Label with text = '%s' created.", labelName);
}
将一个账号标签应用到多个账号
function applyAccountLabels(accountId1, accountId2, labelName) {
  // You can modify this function to accept an array of IDs directly as well.
  const accountIds = [accountId1, accountId2];
  const accounts = AdsManagerApp.accounts().withIds(accountIds).get();
  for (const account of accounts) {
    account.applyLabel(labelName);
    console.log('Label with text = "%s" applied to customer id %s.',
               labelName, account.getCustomerId());
  }
}
从多个账号中移除某个账号标签
function removeLabelFromAccounts(accountId1, accountId2, labelName) {
  const accountIds = [accountId1, accountId2];
  var accounts = AdsManagerApp.accounts().withIds(accountIds).get();
  for (const account of accounts) {
    account.removeLabel(labelName);
    console.log('Label with text = "%s" removed from customer id %s.',
               labelName, account.getCustomerId());
  }
}
按标签名称选择一个账号
function selectAccountsByLabelName(labelName) {
  const accountIterator = AdsManagerApp.accounts()
      .withCondition(`LabelNames CONTAINS '${labelName}'`)
      .get();
  for (const account of accountIterator) {
    const accountName = account.getName() ? account.getName() : '--';
    console.log('%s,%s,%s,%s', account.getCustomerId(), accountName,
        account.getTimeZone(), account.getCurrencyCode());
  }
}
按标签 ID 选择一个账号
function selectAccountsByLabelId(labelId) {
  const label = AdsManagerApp.accountLabels().withIds([labelId]).get().next();
  const accountIterator = label.accounts().get();
  for (const account of accountIterator) {
    const accountName = account.getName() ? account.getName() : '--';
    console.log('%s,%s,%s,%s', account.getCustomerId(), accountName,
        account.getTimeZone(), account.getCurrencyCode());
  }
}
检索所有账号标签
function getAllAccountLabels() {
  const labelIterator = AdsManagerApp.accountLabels().get();
  for (const label of labelIterator) {
    console.log('Label with id = %s and text = %s was found.',
               label.getId().toFixed(0), label.getName());
  }
}
根据名称检索账号标签
function getLabelByName(labelName) {
  const labelIterator = AdsManagerApp.accountLabels()
      .withCondition(`label.name CONTAINS '${labelName}'`)
      .get();
  for (const label of labelIterator) {
    console.log(`Label with id = ${label.getId().toFixed(0)} ` +
        `and text = ${label.getName()} was found.`);
  }
}
根据 ID 检索账号标签
function getLabelById(labelId) {
  const labelIterator = AdsManagerApp.accountLabels()
      .withIds([labelId])
      .get();
  for (const label of labelIterator) {
    console.log("Label with id = %s and text = '%s' was found.",
               label.getId().toFixed(0), label.getName());
  }
}
  
  
  
  
    
  
 
  
    
      
      
    
    
      
    
    
  
       
    
    
      
    
  
  
  如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
  最后更新时间 (UTC):2025-08-21。
  
  
  
    
      [[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-21。"],[],[]]