각 서비스에는 각 REST 메서드의 동기식 메서드와 비동기식 메서드가 모두 포함된 ServiceClient 객체가 있습니다. 다음 예에서는 Network를 동기식으로 읽습니다.
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)
Python 클라이언트 라이브러리는 표준 Python logging 라이브러리를 사용하여 HTTP 요청 및 응답을 로깅합니다. 기본적으로 로깅은 사용 중지되어 있습니다.
로깅을 사용 설정하려면 환경 변수 GOOGLE_SDK_PYTHON_LOGGING_SCOPE를 설정합니다. 이 환경 변수는 logging.DEBUG 이상 수준에서 로깅 이벤트 처리를 구성합니다.
# 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-06(UTC)"],[[["\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/d5df127ea0e7caeda1c4ddedc567d86ca89723c4/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`."]]