소규모 또는 중간 수준의 광고주 또는 엔진 계정 보고서를 요청하는 경우 단일 동기식 보고서 요청만 전송합니다. Search Ads 360 API는 요청에 대한 응답으로 전체 보고서를 JSON 객체로 반환합니다. 동기식 요청:
대규모 광고주 또는 엔진 계정 보고서를 요청하는 경우 비동기 접근 방식이 있습니다.
동기식 요청을 하려면 다음 단계를 따르세요.
Reports.generate()에 전화 걸기
을 사용하여 광고주 또는 엔진 계정 보고서에 원하는 데이터 유형을 지정할 수 있습니다.
Search Ads 360은 요청을 검증하고, 보고서를 생성하고, 보고서를 보고서 리소스로 응답 본문입니다.
동기식 요청의 예
다음은 Reports.generate()의 예입니다.
합니다.
JSON
POST https://www.googleapis.com/doubleclicksearch/v2/reports/generate Authorization: Bearer your OAuth 2.0 access token Content-type: application/json { "reportScope": { "agencyId": "12300000000000456", // Replace with your ID "advertiserId": "21700000000011523", // Replace with your ID "engineAccountId": "700000000073991" // Replace with your ID }, "reportType": "account", // This report covers all revenue and visits in the // engine account specified in reportScope. "columns": [ { "columnName": "date" }, // The date column segments the report by individual days. { "columnName": "dfaRevenue" }, // Here are some metric columns available for keyword { // reports. "columnName": "visits", "startDate": "2013-01-01", // Each metric column can optionally specify its own start "endDate": "2013-01-31", // and end date; by default the report timeRange is used. "headerText": "January visits" // Every column can optionally specify a headerText, which // changes the name of the column in the report. } ], "timeRange" : { "startDate" : "2012-05-01", // Dates are inclusive and specified in YYYY-MM-DD format. "endDate" : "2013-05-01" // Alternatively, try the "changedMetricsSinceTimestamp" or "changedAttributesSinceTimestamp" // options. See Incremental reports. }, "statisticsCurrency": "agency", // Required. See Currency for statistics. "verifySingleTimeZone": false, // Optional. Defaults to false. See Time zone. "includeRemovedEntities": false // Optional. Defaults to false. }
자바
public static void main(String[] args) throws Exception { Doubleclicksearch service = getService(); // See Set Up Your Application. Report report = generateAccountReport(service); outputReport(report, "./"); } /** * Creates an account report using the synchronous Report.generate method. * * @throws IOException */ private static Report generateAccountReport(Doubleclicksearch service) throws IOException { try { return service.reports().generate(generateAccountRequest()).execute(); } catch (GoogleJsonResponseException e) { System.err.println("Report request was rejected."); for (ErrorInfo error : e.getDetails().getErrors()) { System.err.println(error.getMessage()); } System.exit(e.getStatusCode()); return null; // Unreachable code. } } /** * Creates a simple static request that lists the clicks and visits for an engine account. Use * your own agency ID, advertiser ID, and engine account ID. */ private static ReportRequest generateAccountRequest() { return new ReportRequest().setReportScope( new ReportScope() .setAgencyId(20700000000000451L) // Replace with your ID .setAdvertiserId(21700000000010391L) // Replace with your ID .setEngineAccountId(700000000042201L)) // Replace with your ID .setReportType("account") .setColumns(Arrays.asList(new ReportApiColumnSpec[] { new ReportApiColumnSpec().setColumnName("date"), new ReportApiColumnSpec().setColumnName("dfaRevenue"), new ReportApiColumnSpec() .setColumnName("visits") .setHeaderText("January visits") .setStartDate("2013-01-01") .setEndDate("2013-01-31"),})) .setTimeRange(new TimeRange() .setStartDate("2012-05-01") .setEndDate("2013-05-01")) .setStatisticsCurrency("agency"); } /** * Outputs a synchronous report to a file. */ private static void outputReport(Report report, String localPath) throws IOException { FileOutputStream outputStream = new FileOutputStream(new File(localPath, "Report")); final PrintStream printStream = new PrintStream(outputStream); printStream.print(report); printStream.close(); }
Python
def generate_report(service):
"""Generate and print sample report.
Args:
service: An authorized Doubleclicksearch service. See Set Up Your Application.
"""
request = service.reports().generate(
body=
{
"reportScope
"agencyId": "12300000000000456", // Replace with your ID
"advertiserId": "21700000000011523", // Replace with your ID
"engineAccountId": "700000000073991" // Replace with your ID
},
"reportType": "account",
"columns": [
{ "columnName": "date" },
{ "columnName": "dfaRevenue" },
{
"columnName": "visits",
"startDate": "2013-01-01",
"endDate": "2013-01-31",
"headerText": "January visits"
}
],
"timeRange" : {
"startDate" : "2012-05-01",
"endDate" : "2013-05-01"
},
"statisticsCurrency": "agency",
"verifySingleTimeZone": "false",
"includeRemovedEntities": "false"
}
)
pprint.pprint(request.execute())예시 보고서
동기식 요청에 대한 응답은 report 객체입니다.
요청의 유효성 검사에 성공하면 객체의 처음 몇 개의 속성에
제출한 요청을 설명합니다. 보고서 자체는 객체의 rows에 있습니다.
속성
{
"kind":"doubleclicksearch#report",
"request":{
"columns":[
{"columnName":"date"},
{"columnName":"dfaRevenue"},
{"columnName":"visits","endDate":"2013-01-31","headerText":"visits last month","startDate":"2013-01-01"}
],
"includeDeletedEntities":false,
"reportScope":{
"agencyId":"12300000000000456",
"advertiserId":"21700000000011523",
"engineAccountId":"700000000073991"
},
"reportType":"account",
"rowCount":10000,
"startRow":0,
"statisticsCurrency":"agency",
"timeRange":{
"endDate":"2013-05-01",
"startDate":"2012-05-01"
}
},
"rowCount":366,
"rows":[
{
"date":"2012-05-01",
"dfaRevenue":0.0,
"visits last month":0.0
},
{
"date":"2012-05-02",
"dfaRevenue":0.0,
"visits last month":0.0
},
{
"date":"2012-05-03",
"dfaRevenue":0.0,
"visits last month":0.0
},
{
"date":"2012-05-04",
"dfaRevenue":0.0,
"visits last month":0.0
},
...
]
}
검증이 실패하는 경우
보고서가 유효성 검사를 통과하지 못하면 Search Ads 360에서 HTTP 400 응답을 반환합니다.
오류를 반환합니다. 예를 들어 위의 요청 예에서는
대행사:
{
"error": {
"code": 400,
"message": "statisticsCurrency: the agency in scope does not have a valid currency. Please make sure the agency is properly initialized in Search Ads 360."
}
}동기식 보고서를 여러 응답으로 분할
기본적으로 동기식 요청은 처음 10, 000개의 행을 반환합니다. 이 동작을 변경하려면
Reports.request.startRow 사용
및 Reports.request.rowCount
속성을 사용하여 각 요청에서 보고서의 특정 부분을 가져옵니다.
동기식 보고서 분할의 예
예를 들어 이 요청은 대행사 보고서의 처음 100행 (0~99)을 반환합니다. 다음과 같습니다.
{
"reportScope": {
"agencyId": "12300000000000456", // Replace with your ID
"advertiserId": "21700000000011523", // Replace with your ID
"engineAccountId": "700000000073991" // Replace with your ID
},
"reportType": "account",
"columns": [
{ "columnName": "date" },
{ "columnName": "dfaRevenue" }
],
"timeRange" : {
"startDate" : "2012-05-01",
"endDate" : "2013-05-01"
},
"startRow":"0",
"rowCount":"100",
"statisticsCurrency": "agency",
"verifySingleTimeZone": false,
"includeRemovedEntities": false
}
이 요청 다음에 100~199행에 대한 다른 요청을 제출할 수 있습니다.
{
"reportScope": {
"agencyId": "12300000000000456", // Replace with your ID
"advertiserId": "21700000000011523", // Replace with your ID
"engineAccountId": "700000000073991" // Replace with your ID
},
"reportType": "account",
"columns": [
{ "columnName": "date" },
{ "columnName": "dfaRevenue" }
],
"timeRange" : {
"startDate" : "2012-05-01",
"endDate" : "2013-05-01"
},
"startRow":"100",
"rowCount":"100",
"statisticsCurrency": "agency",
"verifySingleTimeZone": false,
"includeRemovedEntities": false
}