使用指南
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
本頁詳細說明如何使用 API 執行常見工作。
建立使用者
UserService 可讓
具備管理員權限的使用者可建立
使用者。任何開發人員都能執行這項操作
讓新使用者先註冊舉例來說,如果您想
當使用者第一次執行 API 呼叫時 (預設值是
電子郵件地址),建議您建立一些具備角色權限的使用者,例如
銷售專員、廣告投放專員或廣告客戶,用於測試真實工作流程。
- 建立新的 Gmail 地址,例如
my.name.salesperson@gmail.com
。另外
將現有的非 Gmail 地址註冊為新
Google 帳戶。
- 使用新地址和所選的
Role
呼叫 createUsers
。
- 您可以使用 OAuth 2.0 產生存取權杖,以新使用者的身分進行驗證。
取得根廣告單元
可新增子節點的頂層 AdUnit
和階層深度取決於您的帳戶類型 (小型商家或 Premium)。支援修改其子節點的最頂層 AdUnit
稱為有效的根 AdUnit
。
如要擷取有效的根,請呼叫 NetworkService.getCurrentNetwork()
,然後檢查回傳 Network
物件的 effectiveRootAdUnitId
欄位。
注意:不同的帳戶類型支援不同的階層模式。
查詢物件
您可以使用 getObjectsByStatement()
方法,透過搜尋條件搜尋物件
許多服務公開,其中 Object 是特定的物件類型。這個
方法會使用 PQL 查詢,這與 SQL 查詢類似,差別在於前者可讓您指定
要搜尋的欄位 (欄位名稱對應至物件屬性)、排序,
並偏移您的搜尋結果詳情請參閱 PQL
指南,進一步瞭解 PQL,以及瞭解有哪些物件欄位可以
篩選依據。
建立訂單
如要建立訂單,只要建立 Order
物件並設定廣告客戶即可
為適當的使用者指派專屬名稱
並呼叫 createOrders()
。結果會包含新建立的 Order
、
或是發生錯誤
範例
請參閱「用於建立訂單的 Java 程式碼」範例。
建立委刊項
建立新委刊項的步驟如下:
- 建立新的
Order
物件或使用現有物件。
- 建立新的
LineItem
物件,並設定輪播類型、廣告素材大小陣列。
開始日期、結束日期和其他屬性
- 建立新的
InventoryTargeting
物件,然後指定要指定或排除的 Placement
或 AdUnit
物件。
- 將
InventoryTargeting
物件納入新的 Targeting
物件中,然後指派
將其加入「LineItem
」的指定資源中。
- 使用新物件呼叫委刊項服務方法
createLineItems()
,然後檢查結果,確認物件是否已建立。
範例
請參閱建立委刊項的 Java 程式碼範例。
製作廣告素材
不同類型的廣告素材支援不同的元件,例如圖片
廣告素材支援單一圖片來源檔案;Flash 廣告素材支援
兩個基礎素材資源檔案:一個 Flash 檔案和一個備用圖片檔案;
則無法放送對於第三方網站代管的廣告素材,請將
只參照第三方伺服器上檔案的 HTML 程式碼片段。查看
特定的 Creative
子類別,瞭解您必須上傳哪些資產
建立廣告素材
範例
請參閱用於建立圖片廣告素材的 Java 程式碼範例。
修改現有物件
如要修改現有物件,請呼叫 getObjectsByStatement()
來查詢物件,
更新傳回物件中的值,然後呼叫 updateObjects()
。
注意:更新後的物件會完全取代現有物件,因此您
無需在傳送的物件中設定屬性值,儲存的物件將
取得該屬性的預設值,而非先前的值。
變更物件狀態
呼叫 performObjectAction()
方法即可變更物件狀態
暴露在風險中。這個方法使用兩個參數:
- 動作物件的執行個體,用於說明您要完成的工作。適用對象
執行個體,訂單服務會公開數個動作,包括
ApproveOrders
、PauseOrders
、
和 ArchiveOrders
。動作物件全都衍生自基本動作
適合服務的類別。
- 描述要變更哪些物件的 PQL 查詢。您可以
方法是指定適當的 PQL 維持狀態
聲明。
您無法使用 API 產生廣告代碼;您必須前往 Google Ad Manager 網站詳情請參閱廣告代碼
說明中心的「
瞭解詳情
更多範例
您可以在我們的用戶端程式庫的範例程式碼中找到更多範例
提供的不同程式設計語言詳情請參閱用戶端程式庫與範例程式碼
」頁面,取得程式設計語言範例的連結。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[[["\u003cp\u003eThis API allows administrators to create and manage users, orders, line items, and creatives directly within their network.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use PQL queries to search and filter objects, similar to SQL, and modify existing objects through updates.\u003c/p\u003e\n"],["\u003cp\u003eDifferent creative types require specific assets; consult the relevant subclass documentation for details.\u003c/p\u003e\n"],["\u003cp\u003eAd tag generation is not supported by the API; use the Google Ad Manager website for this function.\u003c/p\u003e\n"],["\u003cp\u003eAccess further code samples and resources on the Client Libraries & Example Code page.\u003c/p\u003e\n"]]],["The API facilitates several core actions: creating users via `createUsers` with specified roles, and retrieving the effective root AdUnit using `NetworkService.getCurrentNetwork()`. Objects are queried using `get*Objects*ByStatement()`, and orders are created via `createOrders()`. Line items require order creation, then crafting `LineItem`, `InventoryTargeting`, and `Targeting` objects before utilizing `createLineItems()`. Creatives are created with the necessary asset uploads, while object modification involves querying, updating, and using `update*Objects*()`. Object status is changed with the `perform*Object*Action()` method. Ad tags are generated via the Google Ad Manager website.\n"],null,["# How To Guide\n\nThis page provides details on how to perform common tasks using the API.\n\nCreating Users\n--------------\n\nThe [UserService](/ad-manager/api/reference/latest/UserService) allows\na user with Administrator rights to [create\na user](/ad-manager/api/reference/latest/UserService#createUser) directly in their network. Any developer can do this without\nhaving the new user sign up first. For example, if you are trying out the API for\nthe first time, instead of performing every API call as an Administrator (the default\nfor your email address), you may want to create a few users with roles such as\nSalesperson, Trafficker, or Advertiser to test real-world workflows.\n\n1. Create some new gmail addresses such as `my.name.salesperson@gmail.com`. Alternatively, register an existing non-gmail address as a [new\n Google account](http://www.google.com/accounts/NewAccount).\n2. Call `createUsers` with that new address and the chosen [Role](/ad-manager/api/reference/latest/UserService.Role).\n3. You can authenticate as that new user, using [OAuth 2.0](/ad-manager/api/authentication) to generate your access token.\n\nGetting the Root AdUnit\n-----------------------\n\nBoth the topmost `AdUnit` to which you can add child nodes and the permitted depth of your hierarchy depend on your account type (Small Business or Premium). The topmost `AdUnit` that supports modifying its child nodes is called the effective root `AdUnit`.\n\nTo retrieve the effective root, call [NetworkService.getCurrentNetwork()](/ad-manager/api/reference/latest/NetworkService#getCurrentNetwork), and examine the `effectiveRootAdUnitId` field on the returned [Network](/ad-manager/api/reference/latest/NetworkService.Network) object.\n\n**Note:** Different account types support different hierarchy patterns.\n\nQuerying for an Object\n----------------------\n\nYou search for objects by search criteria using the `get`*Objects*`ByStatement()` method\nexposed by many services, where *Object* is a specific object type. This\nmethod takes a PQL query, which is similar to a SQL query in that it lets you specify\nfields to search on (where field names map to properties on the object), sort,\nlimit, and offset your search results. See the [PQL\nGuide](/ad-manager/api/pqlreference) to learn more about PQL, and also to learn which object fields you can\nfilter by.\n\nCreating an Order\n-----------------\n\nTo create an order, simply create an `Order` object and set the advertiser,\nsalesperson, and trafficker IDs to the appropriate users, assign a unique name,\nand call `createOrders()`. The result will include the newly created `Order`,\nor an error.\n\n**Example**\n\nSee example [Java code for creating an order](https://github.com/googleads/googleads-java-lib/blob/main/examples/admanager_axis/src/main/java/admanager/axis/v202508/orderservice/CreateOrders.java).\n\nCreating a Line Item\n--------------------\n\nHere are the steps for creating a new line item:\n\n1. Create a new `Order` object or use an existing one.\n2. Create a new `LineItem` object, and set the rotation type, creative size array, start and end dates, and other properties.\n3. Create a new `InventoryTargeting` object, and specify which `Placement` or `AdUnit` objects to target or exclude.\n4. Wrap your `InventoryTargeting` object inside a new `Targeting` object, and assign it to your `LineItem`'s targeting property.\n5. Call the lineitem service method `createLineItems()` with your new object, and examine the result to see whether your object was created.\n\n**Example**\n\nSee example [Java code for creating a line item](https://github.com/googleads/googleads-java-lib/blob/main/examples/admanager_axis/src/main/java/admanager/axis/v202508/lineitemservice/CreateLineItems.java).\n\nCreating a Creative\n-------------------\n\nDifferent types of creatives support different components: for example, an image\ncreative supports a single source file for the image; a flash creative supports\ntwo underlying asset files: a flash file and a backup image file, in case the flash\nfile cannot be served. For creatives hosted on third-party sites, you will upload\nonly an HTML snippet that references the file on the third-party server. See your\nspecific `Creative` subclass to learn what assets you'll have to upload in order\nto create your creative.\n\n**Example**\n\nSee example [Java code for creating an image creative](https://github.com/googleads/googleads-java-lib/blob/main/examples/admanager_axis/src/main/java/admanager/axis/v202508/creativeservice/CreateCreatives.java).\n\nModifying an Existing Object\n----------------------------\n\nTo modify an existing object, query for your object by calling `get`*Objects*`ByStatement()`,\nupdate the values in the returned objects, and then call `update`*Objects*`()`.\n\n**Note:** Updated objects will completely replace existing objects, so if you\nneglect to set a property value in the object that you send, the saved object will\nget the default value for that property, not the previous value.\n\nChanging Object Status\n----------------------\n\nObject status is changed by calling the `perform`*Object*`Action()` method\nexposed by your service. This method takes two parameters:\n\n- **An instance of the action object that describes what you want done.** For instance, the order service exposes several actions including `ApproveOrders`, `PauseOrders`, and `ArchiveOrders`. Action objects all derive from a base action class appropriate for your service.\n- **A PQL query describing which objects to change.** You can change the status of one or more objects at a time by specifying an appropriate PQL statement.\n\nGenerating Ad Tags\n------------------\n\nYou cannot generate ad tags using the API; instead you must use the Google Ad Manager website. See the [Tagging](https://support.google.com/admanager/answer/177207) Help Center section for\nmore information.\n\nMore Examples\n-------------\n\nYou can find many more examples in our client library sample code, in several\ndifferent programming languages. See the [Client Libraries \\& Example Code](/ad-manager/api/clients) page for a link to examples in your programming language."]]