Để thảo luận và đưa ra ý kiến phản hồi về các sản phẩm của chúng tôi, hãy tham gia kênh Discord chính thức của Ad Manager trong máy chủ Cộng đồng quảng cáo và đo lường của Google.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Google cung cấp một thư viện ứng dụng .NET để tương tác với API Ad Manager.
Bạn nên sử dụng thư viện ứng dụng với NuGet.
Để bắt đầu, hãy tạo một dự án mới trong IDE mà bạn chọn hoặc thêm phần phụ thuộc vào một dự án hiện có. Google phát hành cấu phần phần mềm thư viện ứng dụng vào kho lưu trữ NuGet dưới dạng Google.Ads.AdManager.V1.
ADC tìm thông tin xác thực theo thứ tự ở các vị trí sau:
Biến môi trường GOOGLE_APPLICATION_CREDENTIALS.
Thông tin xác thực người dùng được thiết lập thông qua Google Cloud CLI (gcloud CLI).
Khi chạy trên Google Cloud, tài khoản dịch vụ được đính kèm vào tài nguyên Google Cloud.
Để tạo và định cấu hình thông tin xác thực ADC, hãy xem phần Xác thực.
Tạo yêu cầu đầu tiên
Mỗi dịch vụ có một đối tượng ServiceClient với cả phương thức đồng bộ và không đồng bộ cho mỗi phương thức REST. Ví dụ sau đây đọc Network đồng bộ. Tất cả thực thể được xác định bằng một tên tài nguyên bao gồm loại và giá trị nhận dạng dạng số của thực thể.
usingGoogle.Ads.AdManager.V1;publicsealedpartialclassGeneratedNetworkServiceClientSnippets{publicvoidGetNetwork(){// Create clientNetworkServiceClientnetworkServiceClient=NetworkServiceClient.Create();// Initialize request argument(s)stringname="networks/[NETWORK_CODE]";// Make the requestNetworkresponse=networkServiceClient.GetNetwork(name);}}
Tất cả lỗi API Ad Manager đều thuộc loại
Grpc.Core.RpcException
trong thư viện ứng dụng .NET.
Lỗi bao gồm một request_id duy nhất mà bạn có thể cung cấp cho nhóm hỗ trợ để được trợ giúp khắc phục sự cố. Ví dụ sau trích xuất trạng thái HTTP, thông báo lỗi và request_id.
Thư viện ứng dụng cung cấp các lớp trợ giúp để tạo tên tài nguyên từ mã nhận dạng. Bạn có thể truyền trực tiếp các giá trị này đến các phương thức dịch vụ.
// Represents a resource name in the format:// "networks/{networkCode}/orders/{orderId}"OrderNamename=OrderName.FromNetworkCodeOrder("123","456");Orderresponse=orderServiceClient.GetOrder(name);
Định cấu hình cài đặt proxy
Thư viện ứng dụng .NET tuân theo thuộc tính HttpClient.DefaultProxy, bao gồm cả việc đặt proxy từ các biến môi trường HTTP_PROXY và HTTPS_PROXY. Để biết thêm thông tin, hãy xem Thuộc tính HttpClient.DefaultProxy.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-09-06 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/707317f15750be2b4b07788102e9f445569079ee/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)."]]