Si solicitas informes pequeños o moderados de anunciantes o cuentas de motor, puedes enviar una sola solicitud de informe síncrona En respuesta a la solicitud, la API de Search Ads 360 mostrará el informe completo en un objeto JSON. Solicitudes síncronas:
- Solo puede mostrar el anunciante y de cuenta de motor
- Bloquea a tu cliente hasta que Search Ads 360 genere el informe
Si solicitas informes de anunciantes o cuentas de motor de gran tamaño, te recomendamos la implementación asíncrono enfoque.
Cómo realizar una solicitud síncrona
Llamar al Reports.generate()
para especificar el tipo de datos que quieres incluir en el informe del anunciante o de la cuenta de motor.
Search Ads 360 valida la solicitud, genera el informe y lo muestra como un recurso de informes en el cuerpo de respuesta.
Ejemplo de solicitud síncrona
El siguiente es un ejemplo de Reports.generate()
para cada solicitud.
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. }
Usa la secuencia de comandos de utilidad de Search Ads 360 para enviar esta solicitud
Para enviar una solicitud POST JSON sin procesar, puedes utilizar el archivo sa360Api.py secuencia de comandos de la siguiente manera:
- Copia el objeto JSON de ejemplo (todo lo que está entre los dos y, también, incluye los dos).
llaves) en un nuevo archivo de texto llamado
request.txt
. - Cambie el ID de la agencia que se encuentra en el código JSON por el ID de su propia agencia.
- Quita todos los comentarios, como
// The date column segments the report by individual days.
- Reúne tus credenciales de OAuth 2.0 en una sola cadena separada por comas, como
sigue:
client-ID,client-secret,refresh-token
(Esta es la misma cadena que generasa360Api.py
cuando ejecutassa360Api.py --login
, como se describe en Cómo configurar Autorización). - Invoca a
sa360Api.py
de la siguiente manera:
sa360Api.py --cred CREDENTIALS --server API-method --post < request.txt
En el comando anterior, sustituye la cadena que ensamblaste en el paso anterior porCREDENTIALS
.
Sustituye el nombre del método POST porAPI-method
en el siguiente cuadro.Por ejemplo:
sa360Api.py --cred 123456789123.apps.googleusercontent.com,ABCDEFGHIJKLMNOPQR_abcdef,1/HIJklM01OPQR23NOP456rst890uvw --server https://www.googleapis.com/doubleclicksearch/v2/reports/generate --post < request.txt
Java
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())
Informe de ejemplo
La respuesta a una solicitud síncrona es un objeto report.
Si la solicitud se validó correctamente, las primeras propiedades del objeto contendrán metadatos que
describe la solicitud que enviaste. El informe se encuentra en el rows
del objeto.
propiedad.
{ "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 }, ... ] }
Si la validación falla
Si el informe no aprueba la validación, Search Ads 360 mostrará una respuesta HTTP 400
.
con un objeto de error. Por ejemplo, en la solicitud de ejemplo anterior no se especificó un valor real
agencia:
{ "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." } }
Divide los informes síncronos en varias respuestas
De forma predeterminada, una solicitud síncrona muestra las primeras 10,000 filas. Para cambiar ese comportamiento,
usa el Reports.request.startRow
y Reports.request.rowCount
.
para recuperar partes específicas del informe con cada solicitud.
Ejemplo de división de un informe síncrono
Por ejemplo, esta solicitud devolverá las primeras cien filas (de 0 a 99) de un informe de agencia. segmentada por día:
{ "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 }
Puedes seguir esta solicitud con otra solicitud para las filas 100 a 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 }