apneadiving / google-ads-ruby

Google Ads API Ruby Client Library

Home Page:https://developers.google.com/google-ads/api/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Google Ads Client Library for Ruby

google-ads-googleads uses Google API extensions to provide an easy-to-use client library for the Google Ads API.

Documentation for Users

Getting started

google-ads-googleads will allow you to connect to the Google Ads API and access all its methods.

In order to achieve so you need to set up authentication as well as install the library locally.

Installation

Install this library using gem:

$ [sudo] gem install google-ads-googleads

Alternatively, if you prefer not to or can't use the hosted gem on RubyGems, you can download the gem from the Releases page and install it from the local file:

$ [sudo] gem install google-ads-googleads-[version].gem

Or you can build it yourself from the source. After cloning the GitHub repo, navigate to the google-ads-ruby folder and run:

$ rake build
$ gem install pkg/google-ads-googleads-[version].gem

Set Up Authentication

To authenticate your API calls, you need to specify your client ID, client secret, refresh token, and developer token to the library in one of a few ways.

If you don't have a client ID or client secret yet, please see the Authorization guide to get those set up. Once you have those, the Ruby library can help you use those to generate a refresh token.

See and run the Authentication example to generate your refresh token. Once this is generated, you can provide it to the library in a few different ways.

The simplest is to copy the google_ads_config.rb to your home directory and simply modify it to include the client ID, client secret, and refresh token. The library will automatically read it from the home directory if instantiated with no arguments:

client = Google::Ads::GoogleAds::GoogleAdsClient.new

Alternatively, if you prefer to keep the file elsewhere, you can instantiate the library by passing the path to where you keep this file:

client = Google::Ads::GoogleAds::GoogleAdsClient.new('path/to/file.rb')

If you prefer not to store this information in a file at all, and would rather pass the information programmatically at runtime, you can accomplish that this way:

client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|
  config.client_id = 'INSERT_CLIENT_ID_HERE'
  config.client_secret = 'INSERT_CLIENT_SECRET_HERE'
  config.refresh_token = 'INSERT_REFRESH_TOKEN_HERE'
  config.developer_token = 'INSERT_DEVELOPER_TOKEN_HERE'
end

You can also modify these properties after instantiation by using the configure method on the GoogleAdsClient, using the same structure as above.

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 provided examples for more detailed demonstrations of how to use the library.

Logging

See the instructions in google_ads_config.rb for complete setup.

Logging is set up via the Config object, accessed via client.config or specified in your default config loaded when instantiating a GoogleAdsClient.

You can also specify your own logger by setting client.logger.

Authors

Author:

  • Danial Klimkin
  • Michael Cloonan

Maintainer:

  • Michael Cloonan
  • Sam Phippen

About

Google Ads API Ruby Client Library

https://developers.google.com/google-ads/api/

License:Apache License 2.0


Languages

Language:Ruby 100.0%