示例

本指南包含一些示例,展示了如何在不使用客户端库的情况下直接调用 REST 端点。

前提条件

以下所有示例都可以使用 curl 命令轻松复制并粘贴到 bash shell 中。您需要拥有一个包含至少一个客户账号的 Search Ads 360 经理账号。

环境变量

在下方输入账号凭据和 ID,然后复制并粘贴到终端,以配置后续示例中使用的环境变量。

API_VERSION="0"
OAUTH2_ACCESS_TOKEN="OAUTH_ACCESS_TOKEN"
MANAGER_CUSTOMER_ID="MANAGER_CUSTOMER_ID"
CUSTOMER_ID="CUSTOMER_ID"

其他可选对象 ID

以下示例适用于现有广告系列。如果您有要与这些示例搭配使用的现有广告系列的 ID,请在下方输入。

CAMPAIGN_ID=CAMPAIGN_ID

search 方法使用分页,并在 query 旁边指定可调整的 pageSize 参数。

cURL

#!/bin/bash
# [START curl_command]
curl -f --request POST "https://searchads360.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/searchAds360:search" \
--header "Content-Type: application/json" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"pageSize": 10,
"query": "
  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'
"
}'
# [END curl_command]

SA360 查询语言

  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'

流式

searchStream 方法会在单个响应中流式传输所有结果,因此不支持 pageSize 字段。

cURL

#!/bin/bash
# [START curl_command]
curl -f --request POST "https://searchads360.googleapis.com/v${API_VERSION}/customers/${CUSTOMER_ID}/searchAds360:searchStream" \
--header "Content-Type: application/json" \
--header "login-customer-id: ${MANAGER_CUSTOMER_ID}" \
--header "Authorization: Bearer ${OAUTH2_ACCESS_TOKEN}" \
--data '{
"query": "
  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'
"
}'
# [END curl_command]

SA360 查询语言

  SELECT campaign.name,
    campaign_budget.amount_micros,
    campaign.status,
    campaign.advertising_channel_type,
    metrics.clicks,
    metrics.impressions,
    metrics.ctr,
    metrics.average_cpc,
    metrics.cost_micros,
    campaign.bidding_strategy_type
  FROM campaign
  WHERE segments.date DURING LAST_7_DAYS
    AND campaign.status != 'REMOVED'