ODBC Driver for Facebook

Build 22.0.8462

Linux DSN Configuration

This section describes how to set up ODBC connectivity and configure DSNs on several Linux distributions: Debian-based systems, like Ubuntu, and Red Hat Linux platforms, like Red Hat Enterprise Linux (RHEL), CentOS, and Fedora.

Minimum Linux Versions

Here are the minimum supported versions for Red Hat-based and Debian-based systems:

OSMin. Version
Ubuntu11.04
Debian7
RHEL6.9
CentOS6.9
Fedora13
SUSE12.1

Installing the Driver Dependencies

Run the following commands as root or with sudo to install the necessary dependencies:

  • Debian/Ubuntu:
    apt-get install libc6 libstdc++6 zlib1g libgcc1
  • RHEL/CentOS/Fedora:
    yum install glibc libstdc++ zlib libgcc

Here are the corresponding libraries required by the driver:

Debian/Ubuntu PackageRHEL/CentOS/Fedora PackageFile
libc6glibclinux-vdso.1
libc6glibclibm.so.6
libc6glibclibrt.so.1
libc6glibclibdl.so.2
libc6glibclibpthread.so.0
libc6glibclibc.so.6
libc6glibcld-linux-x86-64.so.2
libstdc++6libstdc++libstdc++.so.6
zlib1gzliblibz.so.1
libgcc1libgcclibgcc_s.so.1

Installing the Driver

You can use standard package management systems to install the driver.

On Debian-based systems, like Ubuntu, run the following command with root or sudo:

dpkg -i /path/to/driver/setup/FacebookODBCDriverforUnix.deb 

On systems that support the RPM package format, run the following command with root or sudo:

rpm -ivh /path/to/driver/FacebookODBCDriverforUnix.rpm 

Licensing the Driver

Run the following commands to license the driver. To activate a trial, omit the <key> input.

cd /opt/cdata/cdata-odbc-driver-for-facebook/bin/
sudo ./install-license.sh <key>

Connecting through the Driver Manager

The driver manager loads the driver and passes function calls from the application to the driver. You need to register the driver with the driver manager and you define DSNs in the driver manager's configuration files.

The driver installation registers the driver with the unixODBC driver manager and creates a system DSN. The unixODBC driver manager can be used from Python and from many other applications. Your application may embed another driver manager.

Creating the DSN

See Using unixODBC to install unixODBC and configure DSNs. See Using the DataDirect Driver Manager to create a DSN to connect to OBIEE, Informatica, and SAS.

Connecting to Facebook

The following are optional connection properties:

  • Target: Some Facebook tables can be filtered by a target. For example, to retrieve comments on a video, specify the Id of the video as the target. This property enables you to restrict the results of all queries in the connection to records that match the specified target. You can also specify this restriction per query with the Target column.
  • AggregateFormat: The driver returns some columns as a string aggregate. For example, the available likes data for an entity is returned in aggregate. By default, the driver returns aggregate columns in JSON. You can also return aggregates in XML.
  • Version: Set this property to the Facebook API version if you need to work with a different version than the default.

Authenticating to Facebook

Facebook uses the OAuth standard to authenticate users.

OAuth

In all OAuth flows, you must set AuthScheme to OAuth. The sections below assume that you have done so.

Desktop Applications

CData provides an embedded OAuth application that simplifies OAuth desktop Authentication. Alternatively, you can create a custom OAuth application. See Creating a Custom AzureAD App for information about creating custom applications and reasons for doing so.

For authentication, the only difference between the two methods is that you must set two additional connection properties when using custom OAuth applications. After setting the following connection properties, you are ready to connect:

  • OAuthClientId: (custom applications only) Set this to the client Id in your application settings.
  • OAuthClientSecret: (custom applications only) Set this to the client secret in your application settings.
  • CallbackURL: Set this to the Redirect URL in your application settings.
  • Scope (optional): Set this if you need to customizie the permissions that the driver requests.
  • AuthenticateAsPage (optional): Set this to a page name or Id to make requests as a page. The page must be managed by the authenticated user.

When you connect the driver opens the OAuth endpoint in your default browser. Log in and grant permissions to the application.

Web Applications

When connecting via a Web application, you need to create and register a custom OAuth application with Facebook. See Creating a Custom OAuth App for more information about custom applications. You can then use the driver to get and manage the OAuth token values. Get an OAuth Access Token

Set the following connection properties to obtain the OAuthAccessToken:

  • AuthScheme: Set this to AzureAD.
  • OAuthClientId: Set this to the client Id in your application settings.
  • OAuthClientSecret: Set this to the client secret in your application settings
  • Scope (optional): Set this if you need to customizie the permissions that the driver requests.
  • AuthenticateAsPage (optional): Set this to a page name or Id to make requests as a page. The page must be managed by the authenticated user.

Then call stored procedures to complete the OAuth exchange:

  1. Call the GetOAuthAuthorizationURL stored procedure. Set the AuthMode input to WEB and set the CallbackURL input to the Redirect URI you specified in your app settings. If necessary, set the "Permissions" parameter to request custom permissions.
  2. Open the URL, log in, and authorize the application. You are redirected back to the callback URL.
  3. Call the GetOAuthAccessToken stored procedure. Set the AuthMode input to WEB. Set the Verifier input to the "code" parameter in the query string of the callback URL. If necessary, set the "Permissions" parameter to request custom permissions.

To connect to data, set the OAuthAccessToken connection property to the access token returned by the stored procedure. When the access token expires after ExpiresIn seconds, call GetOAuthAccessToken again to obtain a new access token.

Headless Machines

To configure the driver to use OAuth with a user account on a headless machine, you need to authenticate on another device that has an internet browser.

Creating a custom OAuth app is optional in the headless OAuth flow; you can skip creating an app by connecting with the driver's embedded OAuth credentials. You might want to create a custom OAuth app to change the information displayed when users log into Facebook to grant permissions to the driver. See Creating a Custom OAuth App for more information about creating custom OAuth applications.

  1. Choose one of these two options:
    • Option 1: Obtain the OAuthVerifier value as described in "Obtain and Exchange a Verifier Code" below.
    • Option 2: Install the driver on another machine and transfer the OAuth authentication values after you authenticate through the usual browser-based flow, as described in "Transfer OAuth Settings" below.
  2. Then configure the driver to automatically refresh the access token from the headless machine.
This section describes the procedure to authenticate and connect to data.

Option 1: Obtain and Exchange a Verifier Code

To obtain a verifier code, you must authenticate at the OAuth authorization URL. Follow the steps below to authenticate from the machine with an internet browser and obtain the OAuthVerifier connection property.

  1. If you are using the Embedded OAuth Application:
    1. Call the GetOAuthAuthorizationURL stored procedure.
    2. Click Facebook OAuth endpoint to open the endpoint in your browser.
  2. If you are using a custom OAuth application, create the Authorization URL by setting the following properties:
    • InitiateOAuth: Set to OFF.
    • OAuthClientId: Set to the client Id assigned when you registered your application.
    • OAuthClientSecret: Set to the client secret assigned when you registered your application.
  3. Call the GetOAuthAuthorizationURL stored procedure with the CallbackURI input parameter set to the exact Redirect URI you specified in your application settings.
  4. Open the URL returned by the stored procedure in a browser.
  5. Log in and grant permissions to the driver. You are then redirected to the callback URL, which contains the verifier code.
  6. Save the value of the verifier code. Later you will set this in the OAuthVerifier connection property.

Finally, on the headless machine, set the following connection properties to obtain the OAuth authentication values:

  • OAuthClientId: Set to the Client ID in your OAuth Integration settings.
  • OAuthClientSecret: Set to the Client Secret in your OAuth Integration settings.
  • OAuthVerifier: Set to the verifier code.
  • OAuthSettingsLocation: Set to persist the encrypted OAuth authentication values to the specified file.
  • InitiateOAuth: Set to REFRESH.

Connect to Data

After the OAuth settings file is generated, set the following properties to connect to data:

  • OAuthSettingsLocation: Set to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
  • InitiateOAuth: Set to REFRESH.

Option 2: Transfer OAuth Settings

To install the driver on another machine, authenticate, and then transfer the resulting OAuth values:

  1. On a second machine, install the driver and connect with the following properties set:
    • OAuthSettingsLocation: Set to a writable text file.
    • OAuthClientId: Set to the client ID in your app settings.
    • OAuthClientSecret: Set to the client secret in your app settings.
    • CallbackURL: Set to the callback URL in your app settings.
  2. Test the connection to authenticate. The resulting authentication values are written and encrypted to the path specified by OAuthSettingsLocation. After you have successfully tested the connection, copy the OAuth settings file to your headless machine. On the headless machine, set the following connection properties to connect to data:
    • InitiateOAuth: Set to REFRESH.
    • OAuthSettingsLocation: Set to the path to your OAuth settings file. Make sure this file gives read and write permissions to the driver to enable the automatic refreshing of the access token.

Requesting Additional Permissions

You may find while using the driver that Facebook returns an error stating your app does not have permissions to do a certain action. To resolve this, you must generate a new OAuth access token with the required permissions. Set the Scope property in the authentication step for a desktop application. You can find a list of available Facebook permissions here:

http://developers.facebook.com/docs/authentication/permissions/

AuthenticateAsPage Property

Use the AuthenticateAsPage connection property if you want to post as a single page. To query collections of pages, leave AuthenticateAsPage blank, in which case CData tools automatically detect which page tokens to use.

The following sections compare the two options.

Posting as a Page

After authenticating to Facebook with your user account, you can post, etc. as one of the pages you manage: Set the AuthenticateAsPage property to the Id of the page you want. You can find the Ids for all pages your account has access to by querying the Pages view.

Automatic Page

Facebook has made a number of recent changes that require page tokens for most resources owned by a page. This can be troublesome if you manage multiple pages and want to execute the same queries across all pages (such as retrieving Insights). In order to make this work seamlessly with our tools, we have added a way to automatically detect the page token to use. For this to work, simply do not specify the AuthenticateAsPage. Note that the correct page token can only be resolved if the page id is specified as part of the target in the request. This means for some requests you will still need to manually specify AuthenticateAsPage.

Refreshing OAuth Values

The driver can refresh the temporary OAuth access tokens obtained during the browser-based OAuth authentication exchange. By default, the driver saves the encrypted tokens in the odbc.ini file corresponding to the DSN. Access to this odbc.ini file can be restricted in the case of System DSNs.

To enable the automatic token exchange, you can give the driver write access to the system odbc.ini.

Installing Dependencies for OAuth Authentication

The OAuth authentication standard requires the authenticating user to interact with Facebook, using a web-browser. 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 needs access to the xdg-open program, which opens the default browser.

To satisfy this dependency, install the corresponding package with your package manager:

Debian/Ubuntu PackageRHEL/CentOS/Fedora PackageFile
xdg-utilsxdg-utilsxdg-open

Set the Driver Encoding

The ODBC drivers need to specify which encoding to use with the ODBC Driver Manager. By default, the CData ODBC Drivers for Unix are configured to use UTF-16 which is compatible with unixODBC, but other Driver Managers may require alternative encoding.

Alternatively, if you are using the ODBC driver from an application that uses the ANSI ODBC API it may be necessary to set the ANSI code page. For example, to import Japanese characters in an ANSI application, you can specify the code page in the config file '/opt/cdata/cdata-odbc-driver-for-facebook/lib/cdata.odbc.facebook.ini':

[Driver]
AnsiCodePage = 932

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8462