--- title: 'Google Ad Api Structure' disqus: hackmd --- ###### tags: `Ads API` `Google Ads` Google Ad Api Structure === [TOC] ## 筆記目的 了解Api的架構,並了解每個層級對應的活動是甚麼 更詳細的內容請參考: * [Google Ad Api structure](https://developers.google.com/google-ads/api/docs/concepts/api-structure) ## 介紹架構 Google Ad Api具有 **hierarchy** 的架構,如圖所示,了解的重點會擺在 ,每個層級是甚麼,還有可以管理甚麼東西 ![](https://i.imgur.com/MQLuM10.png) ![](https://i.imgur.com/UD0nGHK.png) 1. Each account contains one or more active campaigns. 2. Each Campaign contains one or more ad groups, used to group your ads into logical collections. 3. Each AdGroup contains one or more ad group ads. An AdGroupAd represents an ad that you're running. * You can attach one or more AdGroupCriterion or CampaignCriterion to an ad group or campaign. These represent criteria that define how ads get triggered. | 層級 | 涵蓋 | 對應的get操作 | 所需資訊 | |:--------:| -------- | ------------- | -------- | | Account | Campaign | Get campaigns | | | Campaign | Ad Group | Get All Disapproved Ads ,Get ad groups| | Ad Group | Ads | | | | Ad | keyword | 123 | | Get artifact metadata? AD Get expanded text ads? AD Get keywords? AD ## 目前已經完成的 1. GetCampaigns 2. GetAdGroups (need campaingId) 3. GetKeywords (need adGroupId) 4. GetKeywordsStats(dont need adGroupId why?) 5. GetAccountHierarchy 6. GetAllDisapprovedAds 7. GetAccountHierarchy ## 要問的問題 1. https://developers.google.com/google-ads/api/docs/concepts/field-service http request 要怎麼用 他是怎麼使用token的,一般我是直接使用client library去做 ``` https://googleads.googleapis.com/v8/customers/{customer_id}/googleAds:searchStream ``` ``` POST /v8/customers/{customer_id}/googleAds:searchStream HTTP/1.1 Host: googleads.googleapis.com User-Agent: curl Content-Type: application/json Accept: application/json Authorization: Bearer [Enter OAuth 2.0 access token here] developer-token: [Enter developerToken here] Parameters: { "query" : "SELECT campaign.name, campaign.status, segments.device, metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpc, metrics.cost_micros FROM campaign WHERE segments.date DURING LAST_30_DAYS" } ``` 或者是以下這段report的請求,他的access 是怎麼得到的,如果是 ``` https://googleads.googleapis.com/v8/customers/{customer_id}/googleAds:searchStream ``` ``` POST /v8/customers/{customer_id}/googleAds:searchStream HTTP/1.1 Host: googleads.googleapis.com User-Agent: curl Content-Type: application/json Accept: application/json Authorization: Bearer [Enter OAuth 2.0 access token here] developer-token: [Enter developerToken here] Parameters: { "query" : "SELECT campaign.name, campaign.status, segments.device, metrics.impressions, metrics.clicks, metrics.ctr, metrics.average_cpc, metrics.cost_micros FROM campaign WHERE segments.date DURING LAST_30_DAYS" } ``` 2. 如果沒有輸入adgroupid的話應該是要跳出所有Group的關鍵字嗎? 畢竟他有一個@nullable的標籤,我在getkeywords中,沒有放入adGroupId run不起來 Ans 發現adGroupId放置null的話,就會跳出所有關鍵字了 3. how to get adgroupID (for get keywords https://developers.google.com/google-ads/api/docs/samples/get-keywords) Ans run GetAdGroups (need campaingId) 4. get ad names? 5. Fieldname? resoucename? metric(impression 這要去哪裡查?)