> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 取得廣告活動

> 讀取 Google Ads 廣告活動的狀態與每日預算，以及 Google 對其每則廣告或每個素材資源的審核。

取得您透過 Ayrshare 建立的 Google Ads 廣告活動：其名稱、狀態、每日預算，以及 Google 對其每則廣告的審核。

## 請求頭參數

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string`

[Profile Key](https://www.ayrshare.com/docs/apis/overview.md#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

## 路徑參數

**id** `string` *required*

建立廣告活動時返回的 `campaignId`。

## 回應

| 欄位 | 內容 |
| - | - |
| `campaignId` | 廣告活動的 ID |
| `name` | 廣告活動名稱 |
| `campaignStatus` | `active` 或 `paused` |
| `platformStatus` | Google 自身的狀態：`ENABLED`、`PAUSED`，或在 Google Ads 中已刪除的廣告活動為 `REMOVED`。已移除的廣告活動會保留您最後透過 Ayrshare 設定的 `campaignStatus` |
| `budget` | 每日預算：`amount`、`currency`（廣告帳戶的貨幣）及 `type`（`daily`） |
| `ads` | Google 對每則廣告（搜尋）或每個素材資源（Performance Max）的審核。請參閱 [廣告審核](#ad-review) |

## 廣告審核

Google 會依據其廣告政策審核每則新廣告，通常在一個工作天內完成。`ads` 中的每一列包含：

| 欄位 | 內容 |
| - | - |
| `adId` | 廣告的 ID，與建立時返回的相同 |
| `approvalStatus` | Google 的決定：`APPROVED`、`APPROVED_LIMITED`（有限制地顯示，例如不在某些國家/地區顯示）、`AREA_OF_INTEREST_ONLY` 或 `DISAPPROVED`。在 Google 做出決定之前，它會是其他值，例如 `UNKNOWN` 或 `UNSPECIFIED` |
| `reviewStatus` | 審核的進度，例如 `REVIEW_IN_PROGRESS` 或 `REVIEWED` |
| `policyTopics` | 造成限制或未核准的政策：`[{ "topic": "ALCOHOL", "type": "PROHIBITED" }]` |

未核准的廣告不會投放。請在 Google Ads 中修改它，或使用符合規範的文字建立新的廣告活動。若當下無法讀取 Google 的審核結果，或讀取耗時超過數秒，則會省略 `ads`；請稍後再次讀取該廣告活動。

Ayrshare 每晚也會檢查每項審核，並在 Google 的決定變更時傳送 `type: "reviewChanged"` 的 `ads` webhook。請參閱 [Ads 動作](https://www.ayrshare.com/docs/apis/webhooks/actions.md#ads-action)。

## 素材資源審核

Google 會個別審核 Performance Max 廣告活動的每個素材資源。`ads` 會為每個素材資源包含一列，包含與 [廣告審核](#ad-review) 相同的欄位，另外還有：

| 欄位 | 內容 |
| - | - |
| `adId` | 素材資源在此廣告活動中的鍵值：`asset:<assetGroupId>~<assetId>~<fieldType>`，品牌素材資源則為 `asset:<campaignId>~<assetId>~<fieldType>` |
| `assetId` | Google 為該素材資源指定的 ID |
| `fieldType` | 其使用位置，例如 `HEADLINE`、`MARKETING_IMAGE`、`SQUARE_MARKETING_IMAGE`、`BUSINESS_NAME` 或 `LOGO` |
| `primaryStatus` | 是否可以投放，例如 `ELIGIBLE` 或 `NOT_ELIGIBLE` |

商家名稱、標誌和橫向標誌屬於品牌素材資源，會連結至廣告活動而非素材資源群組。它們在這裡也有對應的列，排在素材資源群組的列之後，以廣告活動 ID 為鍵值：`asset:<campaignId>~<assetId>~<fieldType>`，其中 `fieldType` 為 `BUSINESS_NAME`、`LOGO` 或 `LANDSCAPE_LOGO`。

## 錯誤

| 代碼 | 發生時機 |
| - | - |
| `400` | 廣告活動不屬於您、不存在，或已不在該 Google Ads 帳戶中。當您連結的 Google 使用者無法存取該廣告帳戶，或 Google Ads 存取權已被撤銷時，也會返回此錯誤。 |
| `370` | Google 無法完成請求。請再試一次。 |

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-X GET "https://api.ayrshare.com/api/ads/google/campaigns/21534567890"
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", {
  method: "GET",
  headers: {
    "Authorization": `Bearer ${API_KEY}`
  }
})
  .then((res) => res.json())
  .then((json) => console.log(json))
  .catch(console.error);
```

```python Python theme={"system"}
import requests

headers = {
    "Authorization": "Bearer API_KEY",
}

r = requests.get("https://api.ayrshare.com/api/ads/google/campaigns/21534567890", headers=headers)

print(r.json())
```

```php PHP theme={"system"}
<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.ayrshare.com/api/ads/google/campaigns/21534567890",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer API_KEY"
    ]
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error: " . $err;
} else {
    echo $response;
}
?>
```

```csharp C# theme={"system"}
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program
{
    static async Task Main(string[] args)
    {
        var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer API_KEY");

        var response = await client.GetAsync("https://api.ayrshare.com/api/ads/google/campaigns/21534567890");
        var content = await response.Content.ReadAsStringAsync();

        Console.WriteLine(content);
    }
}
```

```go Go theme={"system"}
package main

import (
    "fmt"
    "io"
    "net/http"
)

func main() {
    req, _ := http.NewRequest("GET", "https://api.ayrshare.com/api/ads/google/campaigns/21534567890", nil)
    req.Header.Add("Authorization", "Bearer API_KEY")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        fmt.Println("Error:", err)
        return
    }
    defer resp.Body.Close()

    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}
```

```java Java theme={"system"}
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class GetCampaign {
    public static void main(String[] args) throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.ayrshare.com/api/ads/google/campaigns/21534567890"))
            .header("Authorization", "Bearer API_KEY")
            .GET()
            .build();

        HttpResponse<String> response = HttpClient.newHttpClient()
            .send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}
```

```ruby Ruby theme={"system"}
require 'net/http'
require 'uri'

uri = URI.parse('https://api.ayrshare.com/api/ads/google/campaigns/21534567890')

request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer API_KEY'

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
  http.request(request)
end

puts response.body
```

```json 200: Search Campaign theme={"system"}
{
  "status": "success",
  "platform": "google",
  "campaignId": "21534567890",
  "name": "Fall sale",
  "campaignStatus": "active",
  "platformStatus": "ENABLED",
  "budget": { "amount": 25, "currency": "USD", "type": "daily" },
  "ads": [
    {
      "adId": "71234567890",
      "approvalStatus": "APPROVED_LIMITED",
      "reviewStatus": "REVIEWED",
      "policyTopics": [{ "topic": "ALCOHOL", "type": "LIMITED" }]
    }
  ]
}
```

```json 200: Performance Max Campaign theme={"system"}
{
  "status": "success",
  "platform": "google",
  "campaignId": "21534567891",
  "name": "Fall sale PMax",
  "campaignStatus": "paused",
  "platformStatus": "PAUSED",
  "budget": { "amount": 40, "currency": "USD", "type": "daily" },
  "ads": [
    {
      "adId": "asset:6512345678~31234567890~HEADLINE",
      "assetId": "31234567890",
      "fieldType": "HEADLINE",
      "primaryStatus": "ELIGIBLE",
      "approvalStatus": "APPROVED",
      "reviewStatus": "REVIEWED",
      "policyTopics": []
    }
  ]
}
```

```json 400: Not Found theme={"system"}
{
  "action": "ads",
  "status": "error",
  "code": 400,
  "message": "Campaign not found or you are not authorized to access it."
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.