importcom.google.ads.admanager.v1.OrderName;// ...// Constructs a String in the format:// "networks/{networkCode}/orders/{orderId}"OrderName.of("123","789");
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-31 (世界標準時間)。"],[[["\u003cp\u003eGoogle provides a Java client library for interacting with the Ad Manager API, recommending its use with Apache Maven or Gradle for project integration.\u003c/p\u003e\n"],["\u003cp\u003eThe library utilizes OAuth2 and Application Default Credentials (ADC) for authentication, prioritizing credentials from environment variables, the Google Cloud CLI, or attached service accounts.\u003c/p\u003e\n"],["\u003cp\u003eEach service offers synchronous and asynchronous methods through \u003ccode\u003eServiceClient\u003c/code\u003e objects, enabling interaction with resources like \u003ccode\u003eNetwork\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eHTTP request and response logging is achieved by setting the logger level to \u003ccode\u003eCONFIG\u003c/code\u003e or higher for \u003ccode\u003ecom.google.api.client.http.HttpTransport\u003c/code\u003e using Java's built-in logging or Log4j.\u003c/p\u003e\n"],["\u003cp\u003eError handling involves utilizing \u003ccode\u003eApiException\u003c/code\u003e and \u003ccode\u003eErrorDetails\u003c/code\u003e for analysis, while resource names are constructed using helper classes provided by the client library.\u003c/p\u003e\n"]]],["The Google Ad Manager API's Java client library, accessible via Maven or Gradle, uses OAuth2 and Application Default Credentials (ADC) for authentication, sourcing credentials from the environment, gcloud CLI, or Google Cloud resources. It facilitates API interaction through `ServiceClient` objects, offering synchronous and asynchronous methods. Logging HTTP requests/responses is enabled through `java.util.logging` or Log4j. The client handles errors, identified by unique error codes and `request_id`, and offers resource name construction tools. Proxy settings are configurable using `http.proxyHost` and `https.proxyHost`.\n"],null,["# Java\n\nGoogle provides a Java client library for interacting with the Ad Manager API.\nWe recommend using the client library with Apache Maven or Gradle.\n\nTo get started, create a new project in the IDE of your choice or add the\ndependency to an existing project. Google publishes client library artifacts to\nthe Maven central repository as\n[`com.google.api-ads/ad-manager`](//central.sonatype.com/artifact/com.google.api-ads/ad-manager). \n\n### Maven\n\n \u003c!-- pom.xml --\u003e\n \u003cdependency\u003e\n \u003cgroupId\u003ecom.google.api-ads\u003c/groupId\u003e\n \u003cartifactId\u003ead-manager\u003c/artifactId\u003e\n \u003cversion\u003e0.1.0\u003c/version\u003e\n \u003c/dependency\u003e\n\n### Gradle\n\n implementation 'com.google.api-ads:ad-manager:0.1.0'\n\nConfigure credentials\n---------------------\n\nThe Java client library uses OAuth2 and [Application Default Credentials](//cloud.google.com/docs/authentication/application-default-credentials)\n(ADC) to authenticate.\n\nADC searches for credentials in order in the following locations:\n\n1. `GOOGLE_APPLICATION_CREDENTIALS` environment variable.\n2. User credentials set up through the Google Cloud CLI (gcloud CLI).\n3. When running on Google Cloud, the service account attached to the Google Cloud resource.\n\nFor creating and configuring your ADC credentials, see\n[Authentication](/ad-manager/api/beta/authentication).\n\nMake your first request\n-----------------------\n\nEach service has a `ServiceClient` object with both synchronous and asynchronous\nmethods for each REST method. The following example reads a [`Network`](/ad-manager/api/beta/reference/rest/v1/networks)\nsynchronously. \n\n import com.google.ads.admanager.v1.GetNetworkRequest;\n import com.google.ads.admanager.v1.Network;\n import com.google.ads.admanager.v1.NetworkName;\n import com.google.ads.admanager.v1.NetworkServiceClient;\n\n public class SyncGetNetwork {\n\n public static void main(String[] args) throws Exception {\n syncGetNetwork();\n }\n\n public static void syncGetNetwork() throws Exception {\n try (NetworkServiceClient networkServiceClient = NetworkServiceClient.create()) {\n GetNetworkRequest request =\n GetNetworkRequest.newBuilder()\n .setName(NetworkName.of(\"[NETWORK_CODE]\").toString())\n .build();\n Network response = networkServiceClient.getNetwork(request);\n }\n }\n } \n https://github.com/googleapis/google-cloud-java/blob/9396cfb50fdd22e7f19901773c8af206306cbfb3/java-admanager/samples/snippets/generated/com/google/ads/admanager/v1/networkservice/getnetwork/SyncGetNetwork.java#L20-L45\n\nFor examples of other methods and resources, see the GitHub repository\n[`googleapis/google-cloud-java`](//github.com/googleapis/google-cloud-java/tree/main/java-admanager/samples/snippets/generated/com/google/ads/admanager/v1).\n\nLog HTTP requests and responses\n-------------------------------\n\nThe `com.google.api.client.http.HttpTransport` class makes all HTTP requests.\nThis class uses\n[`java.util.logging`](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html)\n(JUL) for logging HTTP request and response details, including URL, headers, and\ncontent.\n\nTo enable logging, set the logger for this class to a log level of\n`CONFIG` or higher. The steps for this differ depending on which logging\nimplementation you use. \n\n### JUL\n\nTo enable logging, set `com.google.api.client.http.level` to `CONFIG` or\nhigher in your `logging.properties` file. \n\n handlers=java.util.logging.ConsoleHandler\n com.google.api.client.http.level=CONFIG\n java.util.logging.ConsoleHandler.level=CONFIG\n\nAlternatively, you can enable logging in your Java code. \n\n\n import com.google.api.client.http.HttpTransport;\n import java.util.logging.ConsoleHandler;\n import java.util.logging.Level;\n import java.util.logging.Logger;\n\n public static void enableLogging() {\n Logger logger = Logger.getLogger(HttpTransport.class.getName());\n logger.setLevel(Level.CONFIG);\n ConsoleHandler handler = new ConsoleHandler();\n handler.setLevel(Level.CONFIG);\n logger.addHandler(handler);\n }\n\n### Log4j\n\nIf you use Log4j for logging, you can use the\n[Log4j JDK Logging Adapter](https://logging.apache.org/log4j/2.x/log4j-jul.html)\nto log JUL messages. This can be configured through a `SystemProperty` or by\nusing the `Log4jBridgeHandler` and a JUL `logging.properties` file.\n\n### System Property\n\n -Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager\n\n### Log4j Bridge Handler\n\n handlers = org.apache.logging.log4j.jul.Log4jBridgeHandler\n org.apache.logging.log4j.jul.Log4jBridgeHandler.propagateLevels = true\n\nThese settings write Ad Manager API logs to any Logger with a level of\n`CONFIG` or higher. The following example `log4j2.xml` file configures a\nLogger that writes to `System.out`. \n\n \u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n \u003cConfiguration\u003e\n \u003cAppenders\u003e\n \u003cConsole name=\"Console\" target=\"SYSTEM_OUT\"\u003e\n \u003cPatternLayout pattern=\"%m%n\"/\u003e\n \u003c/Console\u003e\n \u003c/Appenders\u003e\n \u003cLoggers\u003e\n \u003cLogger name=\"com.google.api.client.http.HttpTransport\" level=\"debug\"\u003e\n \u003cAppenderRef ref=\"Console\"/\u003e\n \u003c/Logger\u003e\n \u003cRoot level=\"error\"\u003e\n \u003cAppenderRef ref=\"Console\"/\u003e\n \u003c/Root\u003e\n \u003c/Loggers\u003e\n \u003c/Configuration\u003e\n\nHandle errors\n-------------\n\nAll Ad Manager API errors are subclasses of\n[ApiException](//cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.ApiException)\nin the Java client library.\n\nAll errors except `404 Not Found` and `401 Unauthorized` contain `ErrorDetails`\nwith additional information.\n\n### Parse errors\n\nThe error reason field uniquely identifies error types. Use\nthis field to determine how to handle the error. \n\n ErrorDetails errorDetails = apiException.getErrorDetails();\n if (errorDetails != null) {\n // Unique error code in UPPER_SNAKE_CASE.\n String errorCode = errorDetails.getReason();\n }\n\nAd Manager API errors also include a unique `request_id` you can\nprovide to [support](/ad-manager/api/beta/support) for assistance with\ntroubleshooting. The following example extracts the\n`request_id`. \n\n ErrorDetails errorDetails = apiException.getErrorDetails();\n if (errorDetails != null && errorDetails.getRequestInfo() != null) {\n // Unique request identifier.\n String requestId = errorDetails.getRequestInfo().getRequestId();\n }\n\nConstruct resource names\n------------------------\n\nThe client library provides helper classes for building resource names from\nIDs. \n\n import com.google.ads.admanager.v1.OrderName;\n\n // ...\n\n // Constructs a String in the format:\n // \"networks/{networkCode}/orders/{orderId}\"\n OrderName.of(\"123\", \"789\");\n\nConfigure proxy settings\n------------------------\n\nThe Java client library respects both `http.proxyHost` and `https.proxyHost`\nSystem Property settings. For more details on these settings, see\n[Java networking and Proxies](https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html)."]]