There are a few connectors that you can use to connect to Facebook (Fivetran, CData, Stitch). This post specifically explains how to use CData JDBC Facebook Connector to extract page related data from Facebook.
Note: If you are planning to create a dashboard for Page Insights, we have created a Facebook Page Insights dashboard template in our Industry Dashboard Examples repository that you can reuse and modify as needed. The image below shows how the dashboard looks like.
Scroll down for instructions on how to use CData Facebook connector.
Installing The Connector
If you're a Sisense customer, you can download CData Facebook connector for free from this page. If you haven't upgraded to at least Sisense 7.4, you are going to need to download a trial version. Once the connector expires, please reach out to your Customer Success Manager (CSM) for the full license.
Installing the connector is very easy and straightforward, you just need to run the installer, fill our your information, and follow the instructions (mostly you just need to hit 'Next)'.
- To be able to connect and pull data from Facebook Page, you will need an Admin access to the specific page(s) which you want to get the insights on. Follow this link for more information about Facebook page roles.
- To be able to create a Facebook app, you need to have a Facebook Developer account. Log in here using your personal Facebook credentials to convert your account to a developer account.
- If you are interested in campaign-related data, you will also need an access to your company's Facebook Business Manager account. Follow this link for more information about Facebook Business Manager.
Once you have all the prerequisites, follow these steps to continue connecting to Facebook.
1. Creating A Facebook App
Facebook requires that you create an app to access any of their products or APIs. Therefore, the first step that you need to do is to create an app on https://developers.facebook.com/apps and get your App ID and App Secret.
Click on My Apps on the page menu and select + Create App.
When prompted, enter the name of your app as well as you email address, then hit Create App ID.
Once your app is created, go to Settings on the left panel of the screen, and choose Basic. While App ID and App Secret are automatically generated, you need to fill out at least these fields:
- Display Name
- App Domains: you can just put localhost
- Contact Email
- At the bottom of the page, click + Add Platform and select Website. Enter your website URL. You can also use http://localhost if you don't have any website to use.
2. Getting An Access Token
Once your app is created, the next step is creating an access token. Access token is needed any time an app calls Facebook API to read, modify or write Facebook data.
To get an access token, go to https://developers.facebook.com/tools/explorer. From the Application dropdown, select the app that you just created, then select Get User Access Token from the Get Token dropdown.
On the Select Permissions window, select the permissions that are relevant for your use case. At the very least, you need to select manage_pages to be able to get page insights data. Follow this link for more information on Facebook permissions.
Click Get Access Token. Your access token will automatically populated in the Access Token box.
3. Extending Access Token Validity
When you first generate the access token, it is short-lived and will expire in an hour, which means you will no longer be able to use the same token to connect to Facebook an hour later. To be able to connect to Facebook without interruption, you need to convert this token to a long-lived, never expiring one.
To do this, go to https://developers.facebook.com/tools/debug/accesstoken/. Enter your access token in the box, then hit Debug. Once your token is verified, at the bottom of the table, click Extend Access Token.
Your new long-lived token will be provided at bottom of the table. Click the Debug button to verify the new token is a long-lived one. Note that, at first, it might say that the new access token will expire in about 2 months, but it will change to Never expire in a few minutes.
4. Creating Connecting String
Now that you have all the information that you need to be authenticated to Facebook API, you can create the connection string to actually connect Sisense to Facebook.
CData provides a tool that you can use to easily construct the connection string. In the installation folder, look for a Java program file called "cdata.jdbc.facebook.jar". It will most likely be in this location, unless you chose a different directory when you install the connector: C:\Program Files\CData\CData JDBC Driver for Facebook 2019\lib\
Run the program and fill out these fields:
- Authenticate As Page: <Your Page ID*>
- Initiate OAuth: GETANDREFRESH
- OAuth Access Token: <Your Long-Lived Access Token>
- OAuth Client Id: <Your App ID>
- OAuth Client Secret: <Your App Secret>
* Your Page ID is located under About on your Facebook page.
You can also fill out or modify the default values for the other parameters as needed. Once you're done, click on the Test Connection button at the bottom of the window. This will open a Facebook login / permission page. Log in and select Allow permissions when prompted.
Go back to the program and your connection string should be automatically populated in the Connecting String box at the bottom. Click Copy to Clipboard to copy it.
5. Importing Data
The last step is to create a JDBC connection on Sisense and finally start importing data. To create the connection:
- Create or open an Elasticube on the Data tab (Web Elasticube) on your Sisense page, and click on the + Data button.
- Select Generic JDBC from the list of data sources and hit Next.
- In Connection String, paste the connection string that you copied from the previous step.
- In JDBC JARs folder, enter the location of the connector library files. It will most likely be in this location: C:\Program Files\CData\CData JDBC Driver for Facebook 2019\lib.
- In Driver's Class Name, enter cdata.jdbc.facebook.FacebookDriver.
- Leave the User Name and Password fields blank then hit Next.
You should now be able to see the list of tables that you can import from Facebook.
You can find the description of each table in CData data model documentation.
Common Error Messages And Possible Solutions