Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
172 lines (121 sloc) 5.53 KB
= Google adwords4r Library
Welcome to adwords4r: Bringing the delights of Ruby programming to the AdWords
Documentation and comments are a work in progress.
= Useful Web Resources
- {AdWords home}[]
- {AdWords API discussion forum}[]
- {AdWords API documentation}[]
- {This project's Google Code page}[]
= Docs for Users
== 1 - Installation:
adwords4r is a ruby gem. See
Install it using the gem install command.
$ gem install --remote adwords4r
The following gem libraries are required:
- soap4r v1.5.8
- httpclient v2.1.2 or greater
== 2 - Using the client library:
It's pretty easy to use.
See for how to set the rubygem
$ export RUBYOPT=rubygems
$ ruby -rubygems my_program_that_uses_gems
If you do not use the rubygems option, you need to add
require 'rubygems'
at the beginning of your programs.
require 'adwords4r'
adwords =
creates a driver for the latest version of AdWords API using a credentials file
in ENV['HOME']/
There is an example credentials in the root adwords4r directory.
You can also pass API a manually constructed AdWordsCredentials object like:
adwords ={
'developerToken' => 'DEVELOPER_TOKEN',
'applicationToken' => 'APPLICATION_TOKEN',
'useragent' => 'Ruby Sample',
'password' => 'PASSWORD',
'email' => ''
'clientEmail' => '',
'environment' => 'PRODUCTION',
Then, just specify which service you're looking to use, and which version:
account_srv = adwords.get_service(13, 'Account')
and you should now be able to just use the API methods in the object you were
client_accounts = account_srv.getClientAccounts
See the code in the examples directory for working examples you can build from.
*Note*: if your setup requires you to send connections through a proxy server,
please set the HTTP_PROXY environment variable. For example, from your code:
$ ENV['HTTP_PROXY'] = 'http://myproxyserver:8080'
=== 2.1 - Using the Sandbox and other environments:
In order to use the v13 and v2009 sandboxes, make sure that the 'environment'
parameter in the credentials is set to SANDBOX.
Should you need to use an environment other than production or sandbox, you can
add it to the list of environments in runtime:
AdWords::Service::add_environment('ENVIRONMENT_NAME', {
13 => 'URL_FOR_v13',
200906 => 'URL_FOR_v200906'
and then use it normally in your code:
credentials.environment = 'ENVIRONMENT_NAME'
Make sure you only include the base URL, that is, the URL up until the "adwords"
part, leaving the version and group out. Here's an example:
AdWords::Service::add_environment('SANDBOX', {
13 => '',
200906 => ''
=== 2.2 - Mixing v13 and v2009:
It's possible to access both the v13 and v2009 sandboxes or production
environments simultaneously. Since both versions share a common backend storage,
it is possible for your application to choose between v13 and v2009 services
at will, mixing and matching them.
The multiple_versions.rb code sample shows you how to build an application using
v13 and v2009 services simultaneously.
=== 2.3 - Logging:
It is often useful to see a trace of the raw SOAP XML being sent and received.
The quickest way of achieving this when debugging your application is by setting
the ADWORDS4R_DEBUG environment variable to TRUE; e.g. in the bash shell:
or from your Ruby code:
This will output the SOAP XML to stderr, which will usually show up in your
terminal window.
There's also the option of logging requests and XML to files. In order to enable
this, you should use the write_to_file method of the loggers inside your
AdWords::API object:
adwords =
The first logs the units spent and the requests made, whereas the second logs
the full SOAP XML being sent and received over the wire. These will be written
to the current directory by default, but you can specify a path as an optional
parameter to log_to_file:
The files will be named request_info and soap_xml, respectively.
= Docs for Developers
$ rake getwsdl
to get the wsdl files
$ rake generate
to regenerate the bindings if needed
$ rake rdoc
to regenerate the project documentation if needed
$ rake package
to package the gem and create a release
$ rake test
to run unit tests on the library
= Copyright/License Info
Copyright 2009, Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.