在使用AdWords API的ReportDefinitionService
时,如果遇到“找不到ReportDefinition”的错误,通常是由于以下几个原因之一:
ACCOUNT_PERFORMANCE_REPORT
、CAMPAIGN_PERFORMANCE_REPORT
等)是AdWords API支持的。以下是一个简单的示例,展示如何使用AdWords API v201809创建一个基本的账户性能报告定义:
import com.google.api.ads.adwords.lib.AdWordsSession;
import com.google.api.ads.adwords.v201809.cm.ReportDefinition;
import com.google.api.ads.adwords.v201809.cm.ReportDefinitionServiceInterface;
import com.google.api.ads.adwords.v201809.cm.ReportType;
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
public class ReportDefinitionExample {
public static void main(String[] args) throws Exception {
// 初始化AdWords会话
AdWordsSession session = new AdWordsSession.Builder()
.fromFile() // 从配置文件加载凭据
.build();
// 获取ReportDefinitionService
ReportDefinitionServiceInterface reportDefinitionService =
session.getEffectiveAccount().getService(ReportDefinitionServiceInterface.class);
// 创建报告定义
ReportDefinition reportDefinition = new ReportDefinition();
reportDefinition.setReportType(ReportType.ACCOUNT_PERFORMANCE_REPORT);
reportDefinition.setDateRangeType("LAST_7_DAYS");
reportDefinition.setDownloadFormat("CSV");
// 创建报告定义操作
ReportDefinitionOperation operation = new ReportDefinitionOperation();
operation.setOperand(reportDefinition);
operation.setOperator(Operator.ADD);
// 执行操作并获取响应
ReportDefinitionReturnValue result = reportDefinitionService.mutate(new ReportDefinitionOperation[] {operation});
// 输出报告定义ID
System.out.printf("Report definition with ID %d was created.%n", result.getValue()[0].getId());
}
}
领取专属 10元无门槛券
手把手带您无忧上云