【问题标题】:Getting list of fields available for a specific Adwords Report through Google Adwords API通过 Google Adwords API 获取可用于特定 Adwords 报告的字段列表
【发布时间】:2016-06-29 20:45:44
【问题描述】:

有什么方法可以让我使用 Google Adwords API 获取特定报告的所有可用字段列表。我正在使用 Adwords API 版本 201605。

例如,

    selector.getFields().addAll(Lists.newArrayList("CampaignId",
    "AdGroupId",
    "Id",
    "AdNetworkType2",
    "CriteriaType",
    "Criteria",
    "FinalUrls",
    "Impressions",
    "Clicks",
    "Cost"));

这就是我在报告中选择我需要的字段的方式。但是每个报告都有 90 多个字段可用。我需要选择我的案例中的所有字段。那么,adwords api 中是否有类似于以下代码的内容:

    selector.getFields().addAll(Report.getFields("ReportType")));

【问题讨论】:

    标签: java google-ads-api


    【解决方案1】:

    如果以后有人遇到这种情况,至少从 v201708 开始(可能还有早期版本),您可以执行以下操作。

    https://developers.google.com/adwords/api/docs/samples/java/reporting#get-report-fields

    public class GetReportFields {
    
      public static void main(String[] args) throws Exception {
        // Generate a refreshable OAuth2 credential.
        Credential oAuth2Credential = new OfflineCredentials.Builder()
            .forApi(Api.ADWORDS)
            .fromFile()
            .build()
            .generateCredential();
    
        // Construct an AdWordsSession.
        AdWordsSession session = new AdWordsSession.Builder()
            .fromFile()
            .withOAuth2Credential(oAuth2Credential)
            .build();
    
        AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    
        runExample(adWordsServices, session);
      }
    
      public static void runExample(
          AdWordsServicesInterface adWordsServices, AdWordsSession session) throws Exception {
        // Get the ReportDefinitionService.
        ReportDefinitionServiceInterface reportDefinitionService =
            adWordsServices.get(session, ReportDefinitionServiceInterface.class);
    
        // Get report fields.
        ReportDefinitionField[] reportDefinitionFields =
            reportDefinitionService
                .getReportFields(ReportDefinitionReportType.KEYWORDS_PERFORMANCE_REPORT);
    
        // Display report fields.
        System.out.println("Available fields for report:");
    
        for (ReportDefinitionField reportDefinitionField : reportDefinitionFields) {
          System.out.printf("\t %s(%s) := [", reportDefinitionField.getFieldName(),
              reportDefinitionField.getFieldType());
          if (reportDefinitionField.getEnumValues() != null) {
            for (String enumValue : reportDefinitionField.getEnumValues()) {
              System.out.printf("%s, ", enumValue);
            }
          }
          System.out.println("]");
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-09
      相关资源
      最近更新 更多