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.

referencesruby.md

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

Google Ads API Ruby Setup Reference

This guide outlines how to configure, install, and write your first Google Ads API call using Ruby.

Prerequisites

Step 1: Installation

To get started with the client library, you must install the gem: gem install google-ads-googleads. Run this command directly in your terminal:

gem install google-ads-googleads

Step 2: Configuration (google_ads_config.rb)

[!IMPORTANT] Mandatory Agent Directive (Configuration Loading Order): When guiding a user through the Ruby quickstart, your response MUST explicitly explain the 3-tier configuration loading order used by GoogleAdsClient.new:

  1. An explicit path passed directly to the constructor: GoogleAdsClient.new('/path/to/google_ads_config.rb').
  2. The location specified in the GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable, if set.
  3. Otherwise, the default google_ads_config.rb file located in your user's home directory ($HOME).

Do not omit this explanation in your final output.

Create your configuration file named google_ads_config.rb. For self-contained project environments, it is best practice to keep this file in your project root directory and load it explicitly.

# google_ads_config.rb
Google::Ads::GoogleAds::Config.new do |c|
  c.developer_token = 'INSERT_DEVELOPER_TOKEN_HERE'
  c.client_id = 'INSERT_OAUTH2_CLIENT_ID_HERE'
  c.client_secret = 'INSERT_OAUTH2_CLIENT_SECRET_HERE'
  c.refresh_token = 'INSERT_OAUTH2_REFRESH_TOKEN_HERE'
  # Optional: Required if authenticating with a manager account user to access a client account
  # c.login_customer_id = 'INSERT_LOGIN_CUSTOMER_ID_HERE'
end

Step 3: Write and Run the Quickstart Script

Create get_campaigns.rb. Before passing the Client Customer ID to the API, you must clean customer IDs by removing hyphens (e.g. converting 123-456-7890 to 1234567890).

Below is the complete, self-contained Ruby source code to clean the ID and retrieve campaign details:

require 'google/ads/google_ads'

if ARGV.empty?
  puts "Usage: ruby get_campaigns.rb <CUSTOMER_ID>"
  exit 1
end

# Clean customer ID by removing hyphens
customer_id = ARGV[0].gsub('-', '')

# Determine configuration file path (prefer local workspace config)
local_config = File.expand_path('google_ads_config.rb', __dir__)

client = if File.exist?(local_config)
           # Load explicitly from local workspace
           Google::Ads::GoogleAds::GoogleAdsClient.new(local_config)
         else
           # Fallback to default search paths (GOOGLE_ADS_CONFIGURATION_FILE_PATH environment variable or $HOME/google_ads_config.rb)
           Google::Ads::GoogleAds::GoogleAdsClient.new
         end

query = "SELECT campaign.id, campaign.name, campaign.status FROM campaign ORDER BY campaign.id"

begin
  response = client.service.google_ads.search_stream(
    customer_id: customer_id,
    query: query,
  )
  response.each do |page|
    page.results.each do |row|
      puts "Campaign found: ID = #{row.campaign.id}, Name = '#{row.campaign.name}', Status = #{row.campaign.status}"
    end
  end
rescue Google::Ads::GoogleAds::Errors::GoogleAdsError => e
  e.failure.errors.each do |error|
    puts "Error: #{error.message}"
  end
end

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

ruby get_campaigns.rb XXXXXXXXXX

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