Basic usage

The basic usage of the client library is as follows:

Installation

The recommended way to install is by using bundler. Add a line to your Gemfile (replacing x.y.z with the version number you're interested in):

gem 'google-ads-googleads', '~> x.y.z'

Then run:

$ bundle install

This command uses bundler to update your Gemfile.lock, locking to the exact version of the gem and all dependencies of the gem that were installed. The pessimistic version operator "~> x.y.z" causes bundle update to only install new versions in the x.y.* series, so you must manually opt into new versions by updating your Gemfile again.

Other Installation options

If you are not using bundler, you can use one of these options:

  1. Install this library using gem: terminal $ [sudo] gem install google-ads-googleads
  2. Download the gem from the Releases page and install it from the local file: terminal $ [sudo] gem install google-ads-googleads-[version].gem

Set up Authentication

To authenticate your API calls, follow the instructions on the Authentication and Authorization page.

Usage

To include the gem in your code:

require 'google/ads/google_ads'

To fetch a specific service, for example CampaignService:

client = Google::Ads::GoogleAds::GoogleAdsClient.new
campaign_service = client.service.campaign

See the examples on GitHub for more detailed demonstrations of how to use the library.

After you're familiar with the examples, we also recommend familiarizing yourself with factories, which provides a set of high level convenience methods for working with the Google Ads API.

Error handling

Not every API call will succeed. The server can throw errors if your API calls fail for some reason. It is important to capture API errors and handle them appropriately.

A GoogleAdsException instance is thrown when an API error occurs. It has details to help you figure out what went wrong, and you can set up a helper function to handle the errors. See an example of an error handler on GitHub.