Panduan ini berisi contoh pemanggilan endpoint REST secara langsung, tanpa menggunakan library klien.
Prasyarat
Semua contoh di bawah ini dimaksudkan agar mudah disalin dan ditempel ke dalam bash shell menggunakan perintah curl. Anda memerlukan akun pengelola Search Ads 360 yang berisi minimal satu akun klien.
Variabel lingkungan
Masukkan kredensial dan ID akun di bawah, lalu salin dan tempel ke terminal untuk mengonfigurasi variabel lingkungan yang digunakan dalam contoh berikutnya.
API_VERSION="0"
OAUTH2_ACCESS_TOKEN="OAUTH_ACCESS_TOKEN"
MANAGER_CUSTOMER_ID="MANAGER_CUSTOMER_ID"
CUSTOMER_ID="CUSTOMER_ID"
ID objek opsional tambahan
Contoh berikut berfungsi pada kampanye yang sudah ada. Jika Anda memiliki ID kampanye yang ada untuk digunakan dengan contoh ini, masukkan di bawah.
CAMPAIGN_ID=CAMPAIGN_ID
Penelusuran dengan penomoran halaman
Metode search
menggunakan penomoran halaman, dengan parameter pageSize
yang dapat disesuaikan
yang ditentukan bersama query
.
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]
Bahasa Kueri 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'
Streaming
Metode searchStream
melakukan streaming semua hasil dalam satu respons, sehingga
kolom pageSize
tidak didukung.
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]
Bahasa Kueri 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'