Facebook Pages
Extract your Facebook Pages feed, comments, likes and Insights through the Graph API with queries that set the endpoint, fields and date range.
The feed, comments and likes come from the Page feed (opens in a new tab) endpoint of the Facebook Graph API (opens in a new tab), and Page or Page post metrics from Insights (opens in a new tab).
Before you start
You need
- A Facebook account with access to each Page you want to extract: at least the Analyze task for Insights, and Create content, Moderate or Manage for the feed, comments and likes. You sign in with it when you authorize the configuration, and grant the permissions the consent dialog asks for. Alternatively, have a manually generated access token ready for Direct token insert.
What each tab needs
- Prompt tab Kai, the Kai Agent button in the top bar, on supported stacks. A new Free Plan project has it from the start; elsewhere an organization admin turns it on once: Get started with Kai.
- UI tab a browser.
- CLI / API tab kbagent, connected to your project. The checks only read.
Configuration
Section titled “Configuration”Create a new configuration of the Facebook Pages connector.
Then click Authorize Account to authorize the configuration with access to the Facebook Page you want to extract.
You will be asked for the read_insights,public_profile,pages_show_list,manage_pages permissions (opens in a new tab).
Optionally, you can use Direct token insert to specify a manually generated access token.
You can always revoke the authorization by removing the Keboola data source from the list in the Facebook apps tab (opens in a new tab) (under settings).

From the list of fetched pages associated with the authorized account, select the Facebook pages you want to extract.

Create New Query
Section titled “Create New Query”Click the New Query button and specify what data to extract. If you choose a preconfigured template, all necessary fields will fill in automatically.

The query describes the connector request to be sent to the Facebook Graph API. Knowing the API will make
creating a query easy because all options except name represent the Facebook Graph API request (opens in a new tab) parameters.
The Name option describes the query and is used to prefix all table names resulting from the query. One query can produce multiple tables. If a table name produced by the query matches the query name or its substring trimmed after the last occurrence of an underscore, then the output table name will not be prefixed and the query name will be used instead.
For example, if the query name is posts_insights and the produced table name is insights, the output
table name will be posts_insights. If the query name is foo and the produced table name is likes,
the output table name will be foo_likes.
Endpoint
Section titled “Endpoint”The Endpoint option describes a significant URL part of the request made to the Facebook Graph API.
The absolute URL is in the following form: https://graph.facebook.com/<api_version>/<endpoint>.
A typical example would be the feed (opens in a new tab).
If left empty, the Endpoint option references data of the Facebook Page itself.
For more information, see the list of supported Facebook Graph API Page endpoints (opens in a new tab).
Fields
Section titled “Fields”The Fields option describes data returned from the endpoint. Typically, it is a comma-separated list of
fields but it also can be used to parametrize the fields and nest more endpoints into it.
The feed (opens in a new tab) endpoint returns all
posts created by a Facebook Page. Each post contains fields such as caption, message, created_time
and type. The fields parameter in such case is caption,message,created_time,type.
-
Fields/Endpoint Nesting — Posts can contain comments and these can be included in the fields as well:
caption,message,created_time,type,comments{message,created_time,from}. The comma separated list in between the curly brackets{}specifies fields of the “nested” comment (opens in a new tab) field/endpoint for each post (feed endpoint). This way, more endpoints can be nested and there is no limit of nesting levels. If you wanted to include likes of posts comments, the fields parameter would be:caption,message,created_time,type,comments{message,created_time,from,likes{name,username}}. -
Fields Parametrization — Each field can be parametrized by a dot following a parameter/modifier name and a value in brackets. Typical parameters would be
since,untilorlimit, or modifiers that the particular endpoint offers such asmetricsfor the insights (opens in a new tab) endpoint. An example of parametrized fields:comments.since(2 days ago).until(yesterday){message,created_time,from}orinsights.since(1000 days ago).metric(page_views_total).
The Pages option specifies the Facebook Page that the query will be applied to. It can be chosen from a
list of selected pages after authorization. There is the All Pages option meaning that the query will
be applied to all selected pages. The None option means that the query will not be applied to any pages.
It can be useful when extracting data about the authorized account itself. This option is represented
by the Facebook Graph API parameter ids that is a comma separated list of Page IDs.
Since and Until (Advanced Tab)
Section titled “Since and Until (Advanced Tab)”The Since and Until options represent corresponding Facebook Graph API request parameters and
specify the date range that will be applied to the time based data retrieved by the endpoint. For
example, if the endpoint is feed, then all posts created within the specified since-until range will be retrieved.
The Since/Until parameter is parsed via the strtotime function (opens in a new tab) and can be specified
- absolutely — as a unix timestamp or in the
yyyy-mm-ddformat, or - relatively — e.g.
14 days agoorlast month.
For consistent results, specify both the since and until parameters. It is also recommended that the time range does not exceed 6 months.
Limit (Advanced Tab)
Section titled “Limit (Advanced Tab)”The Limit option represents the Facebook Graph API request parameter limit; it is the maximum number
of objects that may be returned in one page of the request. (The default is 25 and the maximum is 100.)
It is useful when the Facebook Graph API returns an error saying there is too much data requested; in such
cases, lower the limit and run the query again.
Save the query and click Run Component.
Check:
Did the latest job of my Facebook Pages configuration succeed, and which tables did it load, with row counts?Kai only reads here, so it asks for no approval, and its answer links to what it found in your project.
The job ends with status Success and Storage has tables named after the query, for example
foo_likes for a query named foo, as described in Name.
kbagent job list --component-id keboola.ex-facebook-pages --config-id 123456789 --limit 1kbagent storage tablesReplace 123456789 with your configuration ID: status shows whether the job succeeded, and the tables it loaded have the latest last_import_date, with their rows in rows_count.
Output Data Description
Section titled “Output Data Description”The output data represent a tree (opens in a new tab) where each node is an array of objects returned from the Facebook Graph API. The tree is transformed into one or more CSV tables.
Each row of a table represents one object. Each table has the primary key auto-detected during the
extraction, so the table data is imported incrementally. The columns of the output tables represent
fields from the Fields query option. Moreover, each table will always contain the following basic set of columns:
id— ID returned by the Facebook Graph APIex_account_id— ID of the Facebook Page corresponding to the object stored in the rowfb_graph_node— Describes the “vertical position” of the object in the resulting tree. For example, for comments it will bepage_feed_comments, for sub-comments (i.e. comments of comments) it will bepage_feed_comments_comments.parent_id— Refers to theidcolumn of a parent object represented by some other row and table. For instance, if the row is representing a comment object, its parent is a post andparent_idis the ID of the post. The parent object type can be also determined from thefb_graph_nodecolumn as a substring from the beginning until the last occurrence of an underscore. To give an example, iffb_graph_nodecontains the valuepage_feed_comments, the parent object type ispage_feed. The top parent ID is the Facebook Page ID.
Facebook API Version
Section titled “Facebook API Version”You can set the version of the Facebook Graph API that will be applied for all requests made to the API by the Facebook Pages data source connector. Read more about the Graph API versions here (opens in a new tab).

Was this page helpful?
Thank you for helping improve Keboola's documentation!