Linux DSN Configuration
This section shows how to connect to Google AdWords and execute SQL queries from several Linux distributions: Debian-based systems, like Ubuntu, and Red Hat Linux platforms, like Red Hat Enterprise Linux (RHEL), CentOS, and Fedora.
Using a Driver Manager
Before installing the CData ODBC Driver for Google AdWords 2016 on Linux, you will need to install a driver manager. ODBC-compliant applications connect to the driver through a driver manager. After you connect, the driver manager loads the driver and passes function calls from the application to the driver. The driver manager also implements some functions for discovering the registered drivers and DSNs. DSNs can be defined for a specific user or system wide.
Installing unixODBC
Precompiled binaries for the unixODBC driver manager are available for many operating systems.
On Debian-based systems like Ubuntu, you can install unixODBC by running the
following command as root or with sudo:
apt-get install unixODBC unixODBC-devOn Red Hat Enterprise Linux, CentOS, and Fedora, you can install unixODBC with YUM or DNF. For example, run the following command as root or with sudo:
yum install unixODBC unixODBC-develIf binaries are not available for your operating system, you will need to compile unixODBC yourself. Please refer to the unixODBC website for more information about obtaining binaries or compiling unixODBC on your operating system.
Installing the Driver Dependencies
Minimum Linux Versions
Below are the minimum supported versions for Red Hat-based and Debian-based systems:
| OS | Min. Version |
| Ubuntu | 11 |
| Debian | 7 |
| RHEL | 6 |
| CentOS | 6 |
| Fedora | 13 |
Required Libraries and Packages
Below are the libraries required by the driver and their corresponding packages:| Debian/Ubuntu Package | RHEL/CentOS/Fedora Package | File |
| libc6 | glibc | linux-vdso.1 |
| libc6 | glibc | libm.so.6 |
| libc6 | glibc | librt.so.1 |
| libc6 | glibc | libdl.so.2 |
| libc6 | glibc | libpthread.so.0 |
| libc6 | glibc | libc.so.6 |
| libc6 | glibc | ld-linux-x86-64.so.2 |
| libstdc++6 | libstdc++ | libstdc++.so.6 |
| zlib1g | zlib | libz.so.1 |
| libgcc1 | libgcc | libgcc_s.so.1 |
Installing the Packages
You can install the necessary dependencies with the following commands:- Debian/Ubuntu:
apt-get install libc6 libstdc++6 zlib1g libgcc1
- RHEL/CentOS/Fedora:
yum install glibc libstdc++ zlib libgcc
Setting Up OAuth
OAuth requires the authenticating user to interact with Google AdWords, using the browser. The driver facilitates this in various ways as described in the following sections; to complete the authentication guide, first check if your environment needs additional configuration.
If the first OAuth interaction is to be done on the same machine the driver is installed on -- for example, a desktop application -- the driver will need access to the xdg-open program, which opens the default browser.
This OAuth flow is not possible on some systems, such as headless machines, servers, and machines disconnected from the Internet. You can use stored procedures to authenticate without this dependency.
| Debian/Ubuntu Package | RHEL/CentOS/Fedora Package | File |
| xdg-utils | xdg-utils | xdg-open |
Installing the Driver
You can use standard package management systems to easily and quickly install the driver.
On Debian-based systems, like Ubuntu, you can install the driver by running
the following command as root or with sudo:
dpkg -i /path/to/.debOn systems that support the RPM package format, you can install the driver by running the following command as root or with sudo:
rpm -Uvh /path/to/.rpm
Using the unixODBC Configuration Files
You can determine the location of the configuration files on your system by entering the following command into a terminal:
odbcinst -jBelow is an example of the output of this command:
DRIVERS............: /etc/odbcinst.ini SYSTEM DATA SOURCES: /etc/odbc.ini FILE DATA SOURCES..: /etc/ODBCDataSources USER DATA SOURCES..: /home/myuser/.odbc.ini SQLULEN Size.......: 8 SQLLEN Size........: 8 SQLSETPOSIROW Size.: 8The driver installation registers the driver for system-wide use and creates a system DSN with empty values for commonly required properties. Modifying unixODBC's system-wide settings requires elevated permissions; to do so, you can use root or the sudo command.
Configuring a DSN
ODBC data sources are defined in sections in the odbc.ini file.
In addition to the connection properties required to connect to your data source, the Driver property specifies either a driver definition in the odbcinst.ini file or the path to the driver library.
[CData GoogleAdWords Source] Driver = CData ODBC Driver for GoogleAdWords Description = My Description MyConnectionProperty1 = My Value MyConnectionProperty2 = My Value2
You can list the data sources on your system with the following command:
odbcinst -q -s
Google AdWords uses the OAuth authentication standard. The driver facilitates OAuth in various ways as described below.
Authenticating Google or Google Apps Users
Use this OAuth flow to authenticate individual user accounts. In this OAuth flow, the authenticating user interacts with the browser.
Authenticating to Google AdWords
After setting the following connection properties, you are ready to connect:
- DeveloperToken: Set this to the developer token of the AdWords account.
- ClientCustomerId: Set this to the client customer Id of the AdWords account.
- Extracts the access token from the callback URL and authenticates requests.
- Saves OAuth values to be persisted across connections.
- Exchanges the refresh token for a new access token when the old access token expires.
Authenticate with a Service Account
You can use this flow to access Google APIs on behalf of users in a domain. A domain administrator must delegate domain-wide access to the service account. In the service account flow, the OAuthAccessToken signifies that the driver has the same scope of access to Google APIs as the service account.
You will need to register an app to generate a private key. See Advanced Settings to obtain the OAuth values for this flow.
- OAuthJWTCertType: Set this to "PFXFILE".
- OAuthJWTCertPassword: Set this to the password of the .p12 file.
- OAuthJWTCertSubject: Set this to "*" to pick the first certificate in the certificate store.
- OAuthJWTIssuer: Set this to the email address of the service account.
- OAuthJWTCert: Set this to the path to the .p12 file.
- OAuthJWTSubject: Set this to the email address of the user for whom the application is requesting delegate access.
- DeveloperToken: Set this to the developer token of the AdWords account.
- ClientCustomerId: Set this to the client customer Id of the AdWords account.
- Creates and signs the JWT (JSON Web token) with the claim set required by the driver.
- Exchanges the JWT for the access token.
- Submits the JWT for a new access token when the token expires.
Authenticating Web Applications
On headless servers or other machines on which the driver is not authorized to open a browser, the driver cannot obtain the access token automatically. However, it can still automatically refresh the token. To obtain the token, you can call the driver's stored procedures, GetOAuthAuthorizationURL and GetOAuthAccessToken. First, set the InitiateOAuth inside the Other property to one of the following:
- OFF: Indicates that the OAuth flow will be handled entirely by the user. An OAuthAccessToken will be required to authenticate.
- REFRESH: Indicates that the driver will only handle refreshing the OAuthAccessToken. The user will never be prompted by the driver to authenticate via the browser. The user must handle obtaining the OAuthAccessToken and OAuthRefreshToken initially. The OAuth values are persisted in the OAuthSettingsLocation Other property.
- OAuthAccessToken
- OAuthRefreshToken
Refreshing OAuth Values
The driver can not only initiate the OAuth exchange, but also refresh the tokens when they expire. To enable the automatic token exchange, you can give the driver write access to /etc/odbc.ini or set the OAuthSettingsLocation property, an Other property, to persist the encrypted tokens to an alternate file path that the driver has write access to.
Configuring Driver Definitions
The sections of the odbcinst.ini file map a driver name to the driver library. The section begins with the driver name; the Driver property points to the path to the driver library. The driver library is the .so file located by default in /opt/cdata/googleadwords/lib. A Description property can also be provided.
You can list the drivers installed on the system with the following command:
odbcinst -q -d
Testing the Connection
You can use isql, included with unixODBC, to execute SQL queries to Google AdWords from the command line. When testing the connection, use the -v flag to output any messages from the driver manager and the driver.
isql -v "CData GoogleAdWords Source"