SOAP XML 請求和回應標頭

本頁將說明必要的 SOAP XML 要求標頭,以及回應時傳回的標頭。

必要的要求標頭

所有 API SOAP 呼叫的標頭都必須包含 <RequestHeader> 元素;這個元素是在所有服務 WSDL 中定義。用戶端程式庫會使用您提供的值,為您新增此標頭。以下是 <RequestHeader> 所有元素的說明:

元素 說明
<networkCode>

要處理的網路聯播網代碼。提出所有要求 (NetworkService.getAllNetworks()NetworkService.makeTestNetwork() 除外) 時,必須提供網路代碼。

請確認您只使用帳戶登入資訊可用的聯播網代碼。您可以在 Google Ad Manager 網站中前往帳戶的「管理」>「聯播網設定」頁面,在「聯播網代碼」旁找到這個程式碼。

<applicationName> 用於識別應用程式的任意字串名稱。這個名稱會顯示在 Google 的記錄檔中。例如:「我的廣告空間應用程式」或「應用程式_1」。

注意:您的應用程式傳送至 Ad Manager API 的每個請求都必須包含 OAuth2 存取權杖。透過 HTTP 標頭將權杖傳遞為 Authorization: Bearer YOUR_ACCESS_TOKEN

要求示例

以下程式碼是對 getAdUnitsByStatement() 發出 SOAP 要求呼叫,目的是尋找根 AdUnit 的範例。

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
        xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <soapenv:Header>
    <ns1:RequestHeader
         soapenv:actor="http://schemas.xmlsoap.org/soap/actor/next"
         soapenv:mustUnderstand="0"
         xmlns:ns1="https://www.google.com/apis/ads/publisher/v202402">
      <ns1:networkCode>123456</ns1:networkCode>
      <ns1:applicationName>DfpApi-Java-2.1.0-dfp_test</ns1:applicationName>
    </ns1:RequestHeader>
  </soapenv:Header>
  <soapenv:Body>
    <getAdUnitsByStatement xmlns="https://www.google.com/apis/ads/publisher/v202402">
      <filterStatement>
        <query>WHERE parentId IS NULL LIMIT 500</query>
      </filterStatement>
    </getAdUnitsByStatement>
  </soapenv:Body>
</soapenv:Envelope>

注意:如果您的 SOAP 要求造成 Unmarshalling error,請參閱「常見錯誤」的疑難排解提示。

回應標頭

API 傳回的所有回應都包含下列標頭元素。建議您記錄這些值。

元素 說明
<requestId> 識別此請求的專屬識別碼。如有任何支援問題,傳送這個 ID 可協助我們更快找出您的要求。
<responseTime> 網路服務從接收要求到傳送回應所經過的時間。

回應範例

下列程式碼顯示了先前要求的 SOAP 回應範例。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <ResponseHeader xmlns="https://www.google.com/apis/ads/publisher/v202402">
      <requestId>xxxxxxxxxxxxxxxxxxxx</requestId>
      <responseTime>1063</responseTime>
    </ResponseHeader>
  </soap:Header>
  <soap:Body>
    <getAdUnitsByStatementResponse xmlns="https://www.google.com/apis/ads/publisher/v202402">
      <rval>
        <totalResultSetSize>1</totalResultSetSize>
        <startIndex>0</startIndex>
        <results>
          <id>2372</id>
          <name>RootAdUnit</name>
          <description></description>
          <targetWindow>TOP</targetWindow>
          <status>ACTIVE</status>
          <adUnitCode>1002372</adUnitCode>
          <inheritedAdSenseSettings>
            <value>
              <adSenseEnabled>true</adSenseEnabled>
              <borderColor>FFFFFF</borderColor>
              <titleColor>0000FF</titleColor>
              <backgroundColor>FFFFFF</backgroundColor>
              <textColor>000000</textColor>
              <urlColor>008000</urlColor>
              <adType>TEXT_AND_IMAGE</adType>
              <borderStyle>DEFAULT</borderStyle>
              <fontFamily>DEFAULT</fontFamily>
              <fontSize>DEFAULT</fontSize>
            </value>
          </inheritedAdSenseSettings>
        </results>
      </rval>
    </getAdUnitsByStatementResponse>
  </soap:Body>
</soap:Envelope>