Enviar uma solicitação de API

Depois de concluir os pré-requisitos, gere a conta do OAuth 2.0 credenciais e configurar seu cliente, poderá usar os seguintes exemplos de código para criar e recuperar um relatório da API Bid Manager consulta.

Para uma lista completa de métodos da API Bid Manager, consulte a referência Documentação.

Criar uma consulta

Veja um exemplo de como criar uma Relatórios do Video 360 consulta:

Java

// Display name of the query to create.
String displayName = display-name;

// Advertiser ID and campaign ID by which to filter report data.
String advertiserId = advertiser-id;
String campaignId = campaign-id;

// Create the query structure.
Query query = new Query();

// Build and set the metadata object.
QueryMetadata metadata = new QueryMetadata();
metadata.setTitle(displayName);
metadata.setDataRange(new DataRange().setRange("LAST_7_DAYS"));
metadata.setFormat("CSV");
query.setMetadata(metadata);

// Build the parameters object.
Parameters parameters = new Parameters();
parameters.setType("STANDARD");

// Build and assign list of standard reporting dimensions to parameters object.
ArrayList<String> dimensions = new ArrayList<String>();
dimensions.add("FILTER_ADVERTISER_NAME");
dimensions.add("FILTER_ADVERTISER");
dimensions.add("FILTER_ADVERTISER_CURRENCY");
dimensions.add("FILTER_INSERTION_ORDER_NAME");
dimensions.add("FILTER_INSERTION_ORDER");
dimensions.add("FILTER_LINE_ITEM_NAME");
dimensions.add("FILTER_LINE_ITEM");
parameters.setGroupBys(dimensions);

// Build a list of filters.
ArrayList<FilterPair> filters = new ArrayList<FilterPair>();
filters.add(new FilterPair().setType("FILTER_ADVERTISER").setValue(advertiserId));
filters.add(new FilterPair().setType("FILTER_MEDIA_PLAN").setValue(campaignId));

// Set filters in parameters object.
parameters.setFilters(filters);

// Build and assign list of standard reporting metrics to parameters object.
ArrayList<String> metrics = new ArrayList<String>();
metrics.add("METRIC_IMPRESSIONS");
metrics.add("METRIC_BILLABLE_IMPRESSIONS");
metrics.add("METRIC_CLICKS");
metrics.add("METRIC_CTR");
metrics.add("METRIC_TOTAL_CONVERSIONS");
metrics.add("METRIC_LAST_CLICKS");
metrics.add("METRIC_LAST_IMPRESSIONS");
metrics.add("METRIC_REVENUE_ADVERTISER");
metrics.add("METRIC_MEDIA_COST_ADVERTISER");
parameters.setMetrics(metrics);

// Set parameters object in query.
query.setParams(parameters);

// Build and set the schedule object.
QuerySchedule schedule = new QuerySchedule();
schedule.setFrequency("ONE_TIME");
query.setSchedule(schedule);

// Create the query.
Query queryResponse = service.queries().create(query).execute();

// Log query creation.
System.out.printf("Query %s was created.%n", queryResponse.getQueryId());

Python

# Display name of the query to create.
display_name = display-name

# Advertiser ID and campaign ID by which to filter report data.
advertiser_id = advertiser-id
campaign_id = campaign-id

# Build query object with basic dimension and metrics values.
query_obj = {
    "metadata": {
        "title": display_name,
        "dataRange": {"range": "LAST_7_DAYS"},
        "format": "CSV",
    },
    "params": {
        "type": "STANDARD",
        "groupBys": [
            "FILTER_ADVERTISER_NAME",
            "FILTER_ADVERTISER",
            "FILTER_ADVERTISER_CURRENCY",
            "FILTER_INSERTION_ORDER_NAME",
            "FILTER_INSERTION_ORDER",
            "FILTER_LINE_ITEM_NAME",
            "FILTER_LINE_ITEM",
        ],
        "filters": [
            {"type": "FILTER_ADVERTISER", "value": advertiser_id},
            {"type": "FILTER_MEDIA_PLAN", "value": campaign_id}
        ],
        "metrics": [
            "METRIC_IMPRESSIONS",
            "METRIC_BILLABLE_IMPRESSIONS",
            "METRIC_CLICKS",
            "METRIC_CTR",
            "METRIC_TOTAL_CONVERSIONS",
            "METRIC_LAST_CLICKS",
            "METRIC_LAST_IMPRESSIONS",
            "METRIC_REVENUE_ADVERTISER",
            "METRIC_MEDIA_COST_ADVERTISER",
        ],
    },
    "schedule": {"frequency": "ONE_TIME"}
}

# Create query object.
query_response = service.queries().create(body=query_obj).execute()

# Print new query ID.
print(f'Query {query_response["queryId"]} was created.')

PHP

// Display name of the query to create.
$displayName = display-name;

// Advertiser ID and campaign ID by which to filter data.
$advertiserId = advertiser-id;
$campaignId = campaign-id;

// Create the query structure.
$query = new Google_Service_DoubleClickBidManager_Query();

// Build and set the metadata object.
$metadata = new Google_Service_DoubleClickBidManager_QueryMetadata();
$metadata->setTitle($displayName);
$metadata->setFormat("CSV");

$dataRange = new Google_Service_DoubleClickBidManager_DataRange();
$dataRange->setRange("LAST_7_DAYS");
$metadata->setDataRange($dataRange);

$query->setMetadata($metadata);

// Build the parameters object.
$parameters = new Google_Service_DoubleClickBidManager_Parameters();
$parameters->setType("STANDARD");

// Build and assign list of standard reporting dimensions.
$parameters->setGroupBys(
    array(
        "FILTER_ADVERTISER_NAME",
        "FILTER_ADVERTISER",
        "FILTER_ADVERTISER_CURRENCY",
        "FILTER_INSERTION_ORDER_NAME",
        "FILTER_INSERTION_ORDER",
        "FILTER_LINE_ITEM_NAME",
        "FILTER_LINE_ITEM"
    )
);

// Build and assign a list of filters.
$filters = array();
$advertiserFilterPair = new Google_Service_DoubleClickBidManager_FilterPair();
$advertiserFilterPair->setType("FILTER_ADVERTISER");
$advertiserFilterPair->setValue($advertiserId);
array_push($filters, $advertiserFilterPair);

$campaignFilterPair = new Google_Service_DoubleClickBidManager_FilterPair();
$campaignFilterPair->setType("FILTER_MEDIA_PLAN");
$campaignFilterPair->setValue($campaignId);
array_push($filters, $campaignFilterPair);

$parameters->setFilters($filters);

// Build and assign list of standard reporting metrics.
$parameters->setMetrics(
    array(
        "METRIC_IMPRESSIONS",
        "METRIC_BILLABLE_IMPRESSIONS",
        "METRIC_CLICKS",
        "METRIC_CTR",
        "METRIC_TOTAL_CONVERSIONS",
        "METRIC_LAST_CLICKS",
        "METRIC_LAST_IMPRESSIONS",
        "METRIC_REVENUE_ADVERTISER",
        "METRIC_MEDIA_COST_ADVERTISER"
    )
);

// Set parameters object in query.
$query->setParams($parameters);

// Build and set the schedule object.
$schedule = new Google_Service_DoubleClickBidManager_QuerySchedule();
$schedule->setFrequency("ONE_TIME");
$query->setSchedule($schedule);

// Call the API, creating the query.
$queryResult = $this->service->queries->create($query);

printf('Query %s was created.
', $queryResult['queryId']);

Recuperar uma consulta

Este é um exemplo de como recuperar um Display & Relatórios do Video 360 consulta:

Java

// ID of query to retrieve.
Long queryId = query-id;

// Retrieve Display & Video 360 query.
Query queryResponse = service.queries().get(queryId).execute();

// Print display name of query.
System.out.printf(
    "Query ID %s was retrieved with display name %s.%n",
    queryResponse.getQueryId(),
    queryResponse.getMetadata().getTitle()
);

Python

# ID of query to retrieve.
query_id = query-id

# Retrieve Display & Video 360 query
query = service.queries().get(queryId=query_id).execute()

# Print display name of query.
print(
    f'Query ID {query_id} retrieved with display name'
    f' {query["metadata"]["title"]}.'
)

PHP

// ID of a query to retrieve.
$queryId = query-id;

// Retrieve Display & Video 360 query.
$queryResponse = $this->service->queries->get($queryId);

printf(
    'Query ID %s was retrieved with display name %s.
',
$queryId, $queryResponse->getMetadata()->getTitle() );