Windows DSN Configuration
Using the Microsoft ODBC Data Source Administrator
You can use the Microsoft ODBC Data Source Administrator to edit the DSN configuration. Note that the DSN is created during the installation process.
Complete the following steps to edit the DSN configuration:
- Select Start > Search, and enter ODBC Data Sources in the Search box.
- Choose the version of the ODBC Administrator that corresponds to the bitness of your application (32-bit or 64-bit).
- Click the System DSN tab.
- Select the system data source and click Configure.
- Edit the information on the Connection tab and click OK.
Note: For .NET Framework 4.0, the driver distributes Microsoft Visual C++ 2015-2022 Redistributable. For .NET Framework 3.5, the driver distributes Microsoft Visual C++ 2008 Redistributable.
Ensuring Registry Access
The driver stores connection information in the Windows registry. To ensure that the driver can write to the registry, perform either of the following actions:
- Run the calling application as an administrator.
- Connect via a User DSN instead of a System DSN.
Connecting to Facebook Ads
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.
- RetryLevel: Use this property to control automatic query retry for specific ad insights queries and errors.
Authenticating to Facebook Ads
Facebook Ads uses the OAuth standard to authenticate users.
OAuth
Desktop Applications
CData provides an embedded OAuth application that simplifies OAuth desktop Authentication. Alternatively, you can create a custom OAuth application. See Creating an Azure AD Application 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. [
Headless Machines
To configure the driver to use OAuth with a user account on a headless machine, you must authenticate on another device that has an internet browser.
Creating a custom OAuth app is optional in the headless OAuth flow; if you want to skip creating an app, you can connect with the driver's embedded OAuth credentials. However, 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. For information on how to create a custom OAuth application, see Creating a Custom OAuth App.
- 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.
- Configure the driver to automatically refresh the access token from the headless machine.
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.
- If you are using the Embedded OAuth Application:
- Call the GetOAuthAuthorizationURL stored procedure.
- Click Facebook Ads OAuth endpoint to open the endpoint in your browser.
- 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.
- Call the GetOAuthAuthorizationURL stored procedure with the CallbackURI input parameter set to the exact Redirect URI you specified in your application settings.
- Open the URL returned by the stored procedure in a browser.
- Log in and grant permissions to the driver. You are then redirected to the callback URL, which contains the verifier code.
- 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 location.
- 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 location containing the encrypted OAuth authentication values. Make sure this location 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:
- On a second machine, install the driver and connect with the following properties set:
- OAuthSettingsLocation: Set to a writable location.
- 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.
- 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 location of your OAuth settings file. Make sure this location 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/
Note that in some cases, permissions restrictions might not be due to missing but requestable Facebook Ads OAuth permissions, but instead might be due to missing OAuth app features, like Page Public Content Access or Page Public Metadata Access. These features are tied to the OAuth app as a whole, and cannot be approved or denied for individual OAuth access tokens requested by users. Consider Creating a Custom OAuth App if you need access to app features not available with the embedded OAuth app.
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. Alternatively, if you would like to disable this automatic detection and thus require usage of AuthenticateAsPage when querying a page, set AutoDetectPageTokens to "False".The following sections compare the two options.
Posting as a Page
After authenticating to Facebook Ads 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 Ads 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 and leave AutoDetectPageTokens set to "True". 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.
Setting AutoDetectPageTokens to "False" will disable automatic page token detection.