連結產品帳戶

Google Ads API 支援將 Google Ads 帳戶連結至其他產品帳戶。 本指南說明如何使用 API 連結帳戶。

將 Google Ads 帳戶連結至其他產品帳戶時,有兩種不同的連結方式。

邀請流程

如果您有 Google Ads 帳戶的管理員存取權,但沒有產品帳戶的管理員存取權,請使用邀請流程。這個流程適用於下列兩種情況:

  1. 您想連結這兩個帳戶,並為產品帳戶管理員建立邀請。產品帳戶管理員接受邀請,完成帳戶連結程序。
  2. 產品帳戶管理員想連結這兩個帳戶,但無法存取 Google Ads 帳戶。產品帳戶管理員建立邀請,您接受邀請並完成連結過程。

在這個情境中,請使用下列方法:

情境 動作 附註
Scenario 1 建立邀請 使用 ProductLinkInvitationService.CreateProductLinkInvitation 方法建立邀請。status 不應設定 ProductLinkInvitation,Google Ads API 伺服器會在 API 呼叫成功完成後,將此值設為 REQUESTED。為廣告合作夥伴 (AdvertisingPartnerLinkInvitationIdentifier) 建立邀請時,自第 25 版起,advertising_partner_properties.allowed_domain 為必要欄位 (第 24 版和更早版本則為選填欄位)。
檢查邀請狀態 使用 GoogleAdsService.Search 或 GoogleAdsService.SearchStream 查詢 product_link_invitation 資源並檢查其狀態。
Scenario 2 擷取邀請 使用 GoogleAdsService.Search 或 GoogleAdsService.SearchStream 查詢 product_link_invitation 資源。篩選 status = PENDING_APPROVAL 接受或拒絕待處理的邀請。
接受或拒絕邀請 使用 ProductLinkInvitationService.UpdateProductLinkInvitation 方法,將 ProductLinkInvitation 的狀態更新為 ACCEPTED 或 REJECTED。
撤銷邀請 使用 ProductLinkInvitationService.RemoveProductLinkInvitation 方法撤銷現有 ProductLinkInvitation。

這個工作流程可能會擲回下列常見錯誤:

錯誤代碼 說明
ProductLinkInvitationError.PERMISSION_DENIED 顧客沒有執行這項操作的權限。
ProductLinkInvitationError.NO_INVITATION_REQUIRED 由於使用者已具備受邀帳戶的管理員存取權,因此無法建立邀請。使用者應使用 ProductLinkService 直接建立有效連結。

直接連結流程

如果您同時擁有 Google Ads 帳戶和產品帳戶的管理員存取權,請使用直接連結流程。在這種情況下,請直接將 Google Ads 帳戶連結至產品帳戶,而不是傳送邀請。

在這個情境中,請使用下列方法:

動作 附註
建立有效連結 使用 ProductLinkService.CreateProductLink 建立 ProductLink。
停用有效連結 使用 ProductLinkService.RemoveProductLink 移除啟用的 ProductLink。
擷取有效連結 使用 GoogleAdsService.Search 或 GoogleAdsService.SearchStream 查詢 product_link 資源。

這個工作流程可能會擲回下列常見錯誤:

錯誤代碼 說明
ProductLinkError.CREATION_NOT_PERMITTED 系統嘗試使用直接連結流程連結帳戶,但因缺少權限,因此不支援這項操作。使用者應改用 ProductLinkInvitationService 進行邀請流程。
ProductLinkError.INVITATION_EXISTS 由於已有待處理的邀請,因此無法建立連結。

您可以對 product_link 資源執行 GAQL 查詢,擷取與 Google Ads 帳戶相關聯的所有產品連結。

SELECT
  product_link.product_link_id,
  product_link.type
FROM product_link

product_link.type 欄位會指出連結的產品或服務類型。 視 type 而定,product_link 資源中的其他欄位會填入資料,提供連結的詳細資訊。舉例來說,如果類型為 DATA_PARTNER,則 data_partner 欄位會包含已連結資料合作夥伴帳戶的相關資訊。

您可以藉此取得直接連結至 Google Ads 帳戶的外部服務和產品帳戶清單,例如 Merchant Center、Google Ads、廣告合作夥伴或資料合作夥伴。

變更「AccountLinkService」

如果您使用 AccountLinkService 將 Google Ads 帳戶連結至其他產品帳戶,則必須將現有應用程式遷移至先前列出的其中一個工作流程。請針對下列連結類型遷移AccountLinkService,並使用 ProductLinkService:

如果是 ThirdPartyAppAnalyticsLinkIdentifier,請繼續使用 AccountLinkService。