Skip to content

Configuration

mcloonan edited this page Mar 13, 2017 · 2 revisions

Configuration

There are certain pieces of information the client library needs in order to successfully make requests to the APIs it supports, such as client id, client secret, and refresh token.

There are other pieces of information that you can use to customize the client library, such as log level. This guide goes over how to provide these configuration details when instantiating the API and what all the options are.

Instantiation

Using a configuration file

In order to use the library, you need to specify some configuration, whether by file or by passing arguments at runtime. By default, the library will look in your environment home directory for a file called adwords_api.yml or dfp_api.yml, depending on the library you're using.

Alternatively, you can pass it a specific file destination as you instantiate it, like this:

adwords = AdwordsApi::Api.new(filename)

The format of this configuration file is standard YAML with symbols as names. You can see the default files for AdWords and DFP. This results in all field names having a : both before and after the name, for example:

:authentication:
  :method: OAuth2
  :oauth2_client_id: client_id
  # etc.

Note that values are nested. The nesting is important, and if you move a value to a different section, then the library will not be able to see it.

Using a runtime configuration

Lastly, you can specify the entire config in a hash passed to the new Api object, bypassing the file entirely. For example:

adwords = AdwordsApi::Api.new({
  :authentication => {
    :method => 'OAuth2',
    :oauth2_client_id => 'client_id'
    # etc.
  }
})

Configuration Options

authentication

This section pertains to all Within the authentication section, the options are:

  • method: Either OAUTH2 or OAUTH2_SERVICE_ACCOUNT
  • oauth2_client_id: The client ID you set up for your project at the Google API Console Credentials page.
  • oauth2_client_secret: The client secret you set up for your project at that same page.
  • oauth2_token: A section header to add OAuth2 tokens within.
  • access_token: An OAuth2 access token that will allow requests to the API.
  • refresh_token: An OAuth2 refresh token that will allow the library to fetch a new access token if none is provided or the current one expires.
  • issued_at: The time that the access token was issued, for example: 2013-12-11 19:15:11.899607226 -05:00
  • expires_in: The number of seconds after issued_at when the access token will expire, usually 3600.
  • [AdWords API only] developer_token: The developer token you got via your MCC account.
  • [AdWords API only] client_customer_id: The client customer ID of the account you want to access.
  • [AdWords API only] user_agent: The string you want to use to identify your app in the HTTP user agent.
  • [DFP API only] application_name: Your application name, which will be passed along in the request.
  • [DFP API only] network_code: The network on which you want your request to operate.
  • [Optional] oauth2_extra_scopes: An array (wrap the value in [] if you only want to use one) which contains extra scopes to use when generating tokens. This can allow you to use the same token across different APIs.
  • [Web flow only] oauth2_callback: The callback to use with [web authentication flow].(https://developers.google.com/accounts/docs/OAuth2WebServer).
  • [Web flow only] oauth2_state: The state parameter for web authentication flow.
  • [Web flow only] oauth2_access_type: The access type parameter for web authentication flow.
  • [Web flow only] oauth2_prompt: The prompt parameter for web authentication flow.
  • [Service account flow only] oauth2_keyfile: The JSON keyfile to use for authentication via service account.
  • [Service account flow only] oauth2_prn: The email address of the user to impersonate. This field is optional.

service

The service section only has a single option:

  • environment: This should always be set to the value PRODUCTION.

connection

The connection section includes options about how the library connects to the API:

  • enable_gzip: Either true or false. Enables to compress all responses.
  • adapter: What HTTP adapter to use for requests. Default is :httpclient.
  • proxy: What proxy to use, if any. Make sure to include any authentication directly in the URL.

library

The library section holds library-level configurations. There is currently only one:

  • log_level: Can be set to DEBUG for all logs, INFO for just important logs, or other log levels for finer control.