fromgoogle.adsimportadmanager_v1defsample_get_network():# Create a clientclient=admanager_v1.NetworkServiceClient()# Initialize request argument(s)request=admanager_v1.GetNetworkRequest(name="networks/[NETWORK_CODE]",)# Make the requestresponse=client.get_network(request=request)# Handle the responseprint(response)
# Log only Ad Manager API eventsexportGOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.ads.admanager_v1
# Log all Google library eventsexportGOOGLE_SDK_PYTHON_LOGGING_SCOPE=google
[[["容易理解","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-09-05 (世界標準時間)。"],[[["\u003cp\u003eGoogle provides a Python client library, \u003ccode\u003egoogle-ads-admanager\u003c/code\u003e, for seamless interactions with the Ad Manager API, installable via pip.\u003c/p\u003e\n"],["\u003cp\u003eThe client library utilizes Application Default Credentials (ADC) for authentication, prioritizing environment variables, gcloud CLI, and Google Cloud resource service accounts.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can make requests to various Ad Manager services using synchronous or asynchronous methods provided by service-specific client objects.\u003c/p\u003e\n"],["\u003cp\u003eError handling is facilitated through the \u003ccode\u003eGoogleAPIError\u003c/code\u003e base class and its \u003ccode\u003ereason\u003c/code\u003e field, enabling developers to identify and manage issues effectively.\u003c/p\u003e\n"],["\u003cp\u003eProxy settings can be configured using the \u003ccode\u003ehttp_proxy\u003c/code\u003e and \u003ccode\u003ehttps_proxy\u003c/code\u003e environment variables, allowing customization of network communication.\u003c/p\u003e\n"]]],["The content outlines using Google's Python client library for the Ad Manager API. Key actions include installing the `google-ads-admanager` library via PyPI and configuring credentials using OAuth2 and Application Default Credentials (ADC), with environment variables, the Google Cloud CLI, or service accounts. A request is made to read a network, demonstrating synchronous method usage. Error handling is shown using `GoogleAPIError` to get `requestId` and using `e.reason`. It details configuring the proxy settings for the library via `http_proxy` and `https_proxy`.\n"],null,["Google provides a Python client library for interacting with the Ad Manager API.\nWe recommend using the client library with PyPI.\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\nPyPI as [`google-ads-admanager`](//pypi.org/project/google-ads-admanager/). \n\n pip install google-ads-admanager\n\nConfigure credentials\n\nThe Python 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\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\n\n from google.ads import admanager_v1\n\n\n def sample_get_network():\n # Create a client\n client = admanager_v1.NetworkServiceClient()\n\n # Initialize request argument(s)\n request = admanager_v1.GetNetworkRequest(\n name=\"networks/[NETWORK_CODE]\",\n )\n\n # Make the request\n response = client.get_network(request=request)\n\n # Handle the response\n print(response) \n https://github.com/googleapis/google-cloud-python/blob/a72bed46615e7443df7d60c943a57c71cd0ca12f/packages/google-ads-admanager/samples/generated_samples/admanager_v1_generated_network_service_get_network_sync.py#L27-L51\n\nFor examples of other methods and resources, see the GitHub repository\n[`googleapis/google-cloud-python`](//github.com/googleapis/google-cloud-python/tree/main/packages/google-ads-admanager/samples/generated_samples).\n\nLog HTTP requests and responses\n\nThe Python client library library uses the standard Python `logging`\nlibrary to log HTTP requests and responses. By default, logging is disabled.\n\nTo enable logging, set the environment variable\n`GOOGLE_SDK_PYTHON_LOGGING_SCOPE`. This environment variable configures\nhandling of logging events at level `logging.DEBUG` or higher. \n\n # Log only Ad Manager API events\n export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google.ads.admanager_v1\n\n # Log all Google library events\n export GOOGLE_SDK_PYTHON_LOGGING_SCOPE=google\n\nAlternatively, you can use the Python `logging` module: \n\n import logging\n\n from google.ads import admanager_v1\n\n logger = logging.getLogger(\"google.ads.admanager_v1\")\n logger.addHandler(logging.StreamHandler())\n logger.setLevel(logging.DEBUG)\n\nHandle errors\n\nAll API errors extend the base class `GoogleAPIError`.\n\nThe error reason field uniquely identifies error types. Use\nthis field to determine how to handle the error. \n\n try:\n network = client.get_network(request=request)\n print(network)\n except GoogleAPIError as e:\n # Handle error\n print(e.reason)\n\nAd Manager API errors also include a unique `requestId` you can\nprovide to [support](/ad-manager/api/beta/support) for assistance with\ntroubleshooting. The following example extracts the\n`requestId` from a `GoogleAPIError`; \n\n except GoogleAPIError as e:\n requestInfoType = \"type.googleapis.com/google.rpc.RequestInfo\"\n requestInfo = [detail for detail in e.details if detail['@type'] == requestInfoType][0]\n print(requestInfo['requestId'])\n\nConfigure proxy settings\n\nThe Python client library respects environment variable settings `http_proxy`\nand `https_proxy`."]]