This project hosts the .NET client library for the Google Ads API.
- Stub classes for all the supported API versions and services.
- Easy management of credentials, authentication, and session information.
- Docs available in HTML and XML format.
- .NET Framework 4.5.2+
- .NET Standard 2.0
For API and client library updates and news, please follow our Google Ads Developers blog: http://googleadsdeveloper.blogspot.com/.
We provide a zip package for the examples. To run the code examples, follow these steps:
- Download the Google.Ads.GoogleAds.Examples zip file from https://github.com/googleads/google-ads-dotnet/releases/latest.
- Extract the examples zip file into a local folder.
- Open `Google.Ads.GoogleAds.Examples.sln in Visual Studio and build it.
- Follow the instructions on the Authentication guide to create an OAuth2 client ID and Secret.
- Run the
AuthenticateInStandaloneApplication
code example from the Visual Studio project. When prompted, provide the client ID and client secret from the previous step.AuthenticateInStandaloneApplication
performs the authentication and prints the configuration in XML format. Copy the configuration into theApp.config
of theGoogle.Ads.GoogleAds.Examples
project. - Open the Properties dialog for the Examples project by
right clicking
Google.Ads.GoogleAds.Examples
project in the Solution Explorer and selecting the Properties option from the context menu. - Navigate to the Debug Tab and enter the command-line options,
which are of the form
version.examplename
. For instance,V0.GetCampaigns
is the command-line option to runGetCampaigns
in theV0
version of the Google Ads API. - Compile and run the
Google.Ads.GoogleAds.Examples
project.
As an alternative to steps 8-10, each code example has a main()
method, so you can set the appropriate code example as the Startup
object (Select the Application tab on the Examples Properties dialog
and pick the desired class from the "Startup object" dropdown.).
The client library binaries are distributed via Nuget. Add a Nuget reference to the Google.Ads.GoogleAds package in your project to use the client library.
// Create a Google Ads client.
GoogleAdsClient client = new GoogleAdsClient();
// Create the required service.
CampaignServiceClient campaignService =
client.GetService(Services.V0.CampaignService);
// make more calls to service class.
See the Getting Started guide for more details, and examples folder for code examples that show how to use various services.
You can enable logging by adding the following line in your Program.cs before making any API calls.
TraceUtilities.Configure(TraceUtilities.DETAILED_REQUEST_LOGS_SOURCE,
"C:\\logs\\details.log", System.Diagnostics.SourceLevels.All);
In most cases, the logs generated by the client library should provide enough details to troubleshoot your issues. When reaching out to the support forum / aliases, you can either provide the logs (which redacts sensitive information by default), or just share the request ID (which is logged as part of the response log).
If you prefer capturing the request ID yourself, then you need to provide a GoogleResponseMetadata object to capture the request ID, as follows:
GoogleAdsResponseMetadata metadata = new GoogleAdsResponseMetadata(client.Config);
// Add the campaigns.
MutateCampaignsResponse retVal = campaignService.MutateCampaigns(
customerId.ToString(), operations.ToArray(), metadata.CallSettings);
Console.WriteLine(metadata.RequestId);
If the API log doesn't give you enough details, then you can enable more low level logging at grpc
level. Keep in mind that this can get pretty detailed and long. The grpc logs are written to
stderr
, but you can attach your own logger like shown below. You can find all the supported
environment variables here:
https://github.com/grpc/grpc/blob/master/doc/environment_variables.md
Environment.SetEnvironmentVariable("GRPC_VERBOSITY", "DEBUG");
Environment.SetEnvironmentVariable("GRPC_TRACE", "http");
GrpcEnvironment.SetLogger(new ConsoleLogger());