.NET
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
Google은 Ad Manager API와 상호작용하는 .NET 클라이언트 라이브러리를 제공합니다.
NuGet과 함께 클라이언트 라이브러리를 사용하는 것이 좋습니다.
시작하려면 원하는 IDE에서 새 프로젝트를 만들거나 기존 프로젝트에 종속 항목을 추가합니다. Google은 클라이언트 라이브러리 아티팩트를 Google.Ads.AdManager.V1
로 NuGet 저장소에 게시합니다.
패키지 참조
<!-- MyProject.csproj -->
<PackageReference Include="Google.Ads.AdManager.V1" Version="1.0.0-beta01" />
.NET CLI
dotnet add package Google.Ads.AdManager.V1 --version 1.0.0-beta01
.NET 클라이언트 라이브러리는 OAuth2 및 애플리케이션 기본 사용자 인증 정보(ADC)를 사용하여 인증합니다.
ADC는 다음 위치에서 순서대로 사용자 인증 정보를 검색합니다.
GOOGLE_APPLICATION_CREDENTIALS
환경 변수입니다.
- Google Cloud CLI (gcloud CLI)를 통해 설정된 사용자 인증 정보
- Google Cloud에서 실행되는 경우 Google Cloud 리소스에 연결된 서비스 계정입니다.
ADC 사용자 인증 정보를 만들고 구성하는 방법은 인증을 참고하세요.
첫 번째 요청하기
각 서비스에는 각 REST 메서드의 동기식 메서드와 비동기식 메서드가 모두 포함된 ServiceClient
객체가 있습니다. 다음 예에서는 Network
를 동기식으로 읽습니다. 모든 항목은 항목의 유형과 숫자 식별자로 구성된 리소스 이름으로 식별됩니다.
using Google.Ads.AdManager.V1;
public sealed partial class GeneratedNetworkServiceClientSnippets
{
public void GetNetwork()
{
// Create client
NetworkServiceClient networkServiceClient = NetworkServiceClient.Create();
// Initialize request argument(s)
string name = "networks/[NETWORK_CODE]";
// Make the request
Network response = networkServiceClient.GetNetwork(name);
}
}
다른 메서드 및 리소스의 예는 GitHub 저장소 googleapis/google-cloud-dotnet
를 참고하세요.
오류 처리
모든 Ad Manager API 오류는.NET 클라이언트 라이브러리의 Grpc.Core.RpcException 유형입니다.
오류에는 문제 해결을 위해 지원팀에 제공할 수 있는 고유한 request_id
가 포함됩니다. 다음 예에서는 HTTP 상태, 오류 메시지, request_id
를 추출합니다.
using Google.Ads.AdManager.V1;
using Google.Api.Gax.Grpc;
using Google.Rpc;
using Grpc.Core;
try
{
NetworkServiceClient networkServiceClient = NetworkServiceClient.Create();
Network network = networkServiceClient.GetNetwork("networks/[NETWORK_CODE]");
}
catch(RpcException e)
{
// HTTP Status code
StatusCode statusCode = e.Status.StatusCode;
// Error message
string errorMessage = e.Status.Detail;
// Unique request identifier.
RequestInfo requestInfo = e.GetStatusDetail<RequestInfo>();
string requestId = requestInfo?.RequestId ?? "Unexpected null request identifier";
}
리소스 이름 구성
클라이언트 라이브러리는 ID에서 리소스 이름을 빌드하기 위한 도우미 클래스를 제공합니다. 이는 서비스 메서드에 직접 전달할 수 있습니다.
// Represents a resource name in the format:
// "networks/{networkCode}/orders/{orderId}"
OrderName name = OrderName.FromNetworkCodeOrder("123", "456");
Order response = orderServiceClient.GetOrder(name);
.NET 클라이언트 라이브러리는 환경 변수 HTTP_PROXY
및 HTTPS_PROXY
의 프록시 설정을 비롯하여 HttpClient.DefaultProxy
속성을 따릅니다. 자세한 내용은 HttpClient.DefaultProxy 속성을 참고하세요.
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-09-02(UTC)
[null,null,["최종 업데이트: 2025-09-02(UTC)"],[[["\u003cp\u003eGoogle provides a .NET client library, accessible via NuGet, for seamless interaction with the Ad Manager API.\u003c/p\u003e\n"],["\u003cp\u003eThe library utilizes Application Default Credentials (ADC) for authentication, prioritizing environment variables, Google Cloud CLI credentials, and service accounts.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can leverage \u003ccode\u003eServiceClient\u003c/code\u003e objects with synchronous and asynchronous methods to access various Ad Manager resources, such as networks.\u003c/p\u003e\n"],["\u003cp\u003eError handling is facilitated through Grpc.Core.RpcException, providing access to status codes, messages, and request IDs for troubleshooting.\u003c/p\u003e\n"],["\u003cp\u003eResource names can be easily constructed using helper classes, enabling efficient interaction with specific Ad Manager entities.\u003c/p\u003e\n"]]],["The Google Ad Manager API .NET client library, available via NuGet as `Google.Ads.AdManager.V1`, uses OAuth2 and Application Default Credentials (ADC) for authentication. To make requests, create a `ServiceClient` object, and utilize synchronous or asynchronous methods. Resource names, formatted with IDs, can be constructed using helper classes. Error handling involves catching `RpcException`, retrieving the status code, message, and `request_id`. The library also supports proxy configuration through the `HttpClient.DefaultProxy` property and environment variables.\n"],null,["Google provides a .NET client library for interacting with the Ad Manager API.\nWe recommend using the client library with NuGet.\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\nNuGet repository as\n[`Google.Ads.AdManager.V1`](//www.nuget.org/packages/Google.Ads.AdManager.V1). \n\nPackage Reference \n\n \u003c!-- MyProject.csproj --\u003e\n \u003cPackageReference Include=\"Google.Ads.AdManager.V1\" Version=\"1.0.0-beta01\" /\u003e\n\n.NET CLI \n\n dotnet add package Google.Ads.AdManager.V1 --version 1.0.0-beta01\n\nConfigure credentials\n\nThe .NET 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. All entities are identified by a\n[resource name](#construct_resource_names) consisting of the type and numeric\nidentifier of the entity. \n\n using Google.Ads.AdManager.V1;\n\n public sealed partial class GeneratedNetworkServiceClientSnippets\n {\n public void GetNetwork()\n {\n // Create client\n NetworkServiceClient networkServiceClient = NetworkServiceClient.Create();\n // Initialize request argument(s)\n string name = \"networks/[NETWORK_CODE]\";\n // Make the request\n Network response = networkServiceClient.GetNetwork(name);\n }\n } \n https://github.com/googleapis/google-cloud-dotnet/blob/f7caa4b1d158434eb1cf5c4a185428b6419ee32b/apis/Google.Ads.AdManager.V1/Google.Ads.AdManager.V1.GeneratedSnippets/NetworkServiceClient.GetNetworkSnippet.g.cs#L20-L41\n\nFor examples of other methods and resources, see the GitHub repository\n[`googleapis/google-cloud-dotnet`](//github.com/googleapis/google-cloud-dotnet/apis/Google.Ads.AdManager.V1/Google.Ads.AdManager.V1.GeneratedSnippets).\n\nHandle errors\n\nAll Ad Manager API errors are of the type\n[Grpc.Core.RpcException](//cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.RpcException)\nin the .NET client library.\n\nErrors include a unique `request_id` you can\nprovide to [support](/ad-manager/api/beta/support) for assistance with\ntroubleshooting. The following example extracts the HTTP status, error message,\nand `request_id`. \n\n using Google.Ads.AdManager.V1;\n using Google.Api.Gax.Grpc;\n using Google.Rpc;\n using Grpc.Core;\n\n try\n {\n NetworkServiceClient networkServiceClient = NetworkServiceClient.Create();\n Network network = networkServiceClient.GetNetwork(\"networks/[NETWORK_CODE]\");\n }\n catch(RpcException e)\n {\n // HTTP Status code\n StatusCode statusCode = e.Status.StatusCode;\n // Error message\n string errorMessage = e.Status.Detail;\n // Unique request identifier.\n RequestInfo requestInfo = e.GetStatusDetail\u003cRequestInfo\u003e();\n string requestId = requestInfo?.RequestId ?? \"Unexpected null request identifier\";\n }\n\nConstruct resource names\n\nThe client library provides helper classes for building resource names from\nIDs. These can be passed directly to service methods. \n\n // Represents a resource name in the format:\n // \"networks/{networkCode}/orders/{orderId}\"\n OrderName name = OrderName.FromNetworkCodeOrder(\"123\", \"456\");\n Order response = orderServiceClient.GetOrder(name);\n\nConfigure proxy settings\n\nThe .NET client library respects the `HttpClient.DefaultProxy` property\nincluding setting proxies from the environment variables `HTTP_PROXY` and\n`HTTPS_PROXY`. For more details, see\n[HttpClient.DefaultProxy Property](//learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclient.defaultproxy)."]]