有没有办法可以使用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")));
答案 0 :(得分: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("]");
}
}
}