All skills
google avatar

/google-ads-api-quickstart

@329fa26
by googlegoogle/skills21k stars
1,698

Guides developers through Google Ads API quickstart: credential setup, choosing from 6 client libraries/REST, configuring environments, and running a "retrieve campaigns" script. Troubleshoots common setup errors: USER_PERMISSION_DENIED, login_customer_id issues, and DEVELOPER_TOKEN_NOT_APPROVED. Use this skill when: - The user asks how to get started with the Google Ads API. - The user needs to set up Google Ads credentials or developer tokens. - The user wants to write a quickstart/example script for Google Ads. - The user encounters errors like USER_PERMISSION_DENIED or DEVELOPER_TOKEN_NOT_APPROVED.

Use this Skill: https://skilld.dev/gh/google/skills/google-ads-api-quickstart

This session only. Nothing lands on disk.

referencesdotnet.md

≈1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Google Ads API .NET Setup Reference

This guide outlines how to configure, install, and write your first Google Ads API call using .NET/C#.

Prerequisites

Step 1: Installation

Install the official package using NuGet:

dotnet add package Google.Ads.GoogleAds

Step 2: Configuration (Runtime Initialization)

The preferred way to configure the .NET client library is to initialize a GoogleAdsConfig object at runtime. Gather your required credentials to include in your code:

  • Developer Token
  • OAuth2 Client ID
  • OAuth2 Client Secret
  • OAuth2 Refresh Token
  • Login Customer ID (optional, required if authenticating as a manager account)

Alternate Configuration Options

If you prefer external configuration files or environment variables, add a NuGet reference to the Google.Ads.GoogleAds.Extensions package. You must then explicitly load the settings onto your GoogleAdsConfig object:

  • Environment Variables: Call config.LoadFromEnvironmentVariables().
  • App.config: Call config.LoadFromDefaultAppConfigSection().
  • settings.json / Custom JSON: Use ConfigurationBuilder and call config.LoadFromConfigurationRoot(configRoot).

Step 3: Write and Run the Quickstart Script

Create Program.cs. Before passing the Client Customer ID to the API, you must clean customer IDs by stripping hyphens (e.g., converting 123-456-7890 to 1234567890). This ensures standard numeric parsing:

IMPORTANT

Replace VXX and VXX in the namespace and service calls with the latest supported version (e.g., V24) discovered in the Prerequisites step.

using System;
using Google.Ads.GoogleAds.Config;
using Google.Ads.GoogleAds.Lib;
using Google.Ads.GoogleAds.VXX.Services;
using Google.Ads.GoogleAds.VXX.Errors;

class Program {
    static void Main(string[] args) {
        if (args.Length < 1) {
            Console.WriteLine("Usage: dotnet run <CUSTOMER_ID>");
            return;
        }

        // Clean customer ID by stripping hyphens
        string customerId = args[0].Replace("-", "");
        
        GoogleAdsConfig config = new GoogleAdsConfig()
        {
            DeveloperToken = "INSERT_DEVELOPER_TOKEN_HERE",
            OAuth2Mode = OAuth2Flow.APPLICATION,
            OAuth2ClientId = "INSERT_OAUTH2_CLIENT_ID_HERE",
            OAuth2ClientSecret = "INSERT_OAUTH2_CLIENT_SECRET_HERE",
            OAuth2RefreshToken = "INSERT_OAUTH2_REFRESH_TOKEN_HERE",
            // LoginCustomerId = "INSERT_LOGIN_CUSTOMER_ID_HERE"
        };

        // Optional: If using Google.Ads.GoogleAds.Extensions, you can also load overriding environment variables:
        // config.LoadFromEnvironmentVariables();

        GoogleAdsClient client = new GoogleAdsClient(config);
        GoogleAdsServiceClient service = client.GetService(Services.VXX.GoogleAdsService);
        string query = "SELECT campaign.id, campaign.name, campaign.status FROM campaign ORDER BY campaign.id";

        try {
            service.SearchStream(customerId, query, delegate(SearchGoogleAdsStreamResponse response) {
                foreach (GoogleAdsRow row in response.Results) {
                    Console.WriteLine($"Campaign found: ID = {row.Campaign.Id}, Name = '{row.Campaign.Name}', Status = {row.Campaign.Status}");
                }
            });
        } catch (GoogleAdsException ex) {
            Console.WriteLine($"Request failed: ID {ex.RequestId}. Error: {ex.Message}");
        }
    }
}

Run the project (replace XXXXXXXXXX with your 10-digit Client Customer ID):

dotnet run XXXXXXXXXX

Step 4: Verification

Verify the output of your run. A successful execution will stream the campaigns associated with the customer ID to the console, similar to the following:

Campaign found: ID = 987654321, Name = 'Interstate Search Promo', Status = Enabled
Campaign found: ID = 555444333, Name = 'Local Brand Awareness', Status = Paused

Source: SKILL.md on GitHub

1 warning8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill provides a secure and comprehensive guide for developers to integrate with the Google Ads API. It emphasizes the use of official libraries, dynamic version resolution from trusted sources, and secure credential management practices.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: MEDIUM · 2 issues

Signed by skilld at 329fa26. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
Other metadata
compatibility
Outbound HTTPS connectivity required to access the Google Ads API and documentation. Note: If network access is restricted, the agent will fall back to using the last-known stable versions cached within the skill resources.
metadata
{
  "author": "google-ads-api-team",
  "version": "1.0.0",
  "category": "GoogleAds"
}

README badge

README badge for google/skills/google-ads-api-quickstart