Apache Airflow Facebook Provider

3.9.4 · active · verified Fri Apr 17

This provider package integrates Apache Airflow with Facebook APIs, offering operators and hooks to interact with various Facebook services like Marketing and Prophet. It allows data engineers to programmatically manage and automate data workflows involving Facebook platforms. Current version is 3.9.4, with releases tied to the Apache Airflow release cycle.

Common errors

Warnings

Install

Imports

Quickstart

This example DAG uses the `FacebookMarketingOperator` to fetch a list of ad accounts associated with the configured Facebook connection. It requires an Airflow connection named `facebook_marketing_default` with a valid Facebook Access Token. The access token can be stored in the 'Password' field or as part of the 'Extra' JSON for the connection.

from __future__ import annotations

import pendulum
import os

from airflow.models.dag import DAG
from airflow.providers.facebook.marketing.operators.marketing import FacebookMarketingOperator

# NOTE: Ensure you have an Airflow Connection named 'facebook_marketing_default'
# with your Facebook Access Token (e.g., in the 'Password' field or 'Extra' JSON).
# Example Extra: {"access_token": "YOUR_ACCESS_TOKEN", "api_version": "v19.0"}

with DAG(
    dag_id="facebook_marketing_example",
    start_date=pendulum.datetime(2023, 1, 1, tz="UTC"),
    schedule=None,
    catchup=False,
    tags=["facebook", "marketing", "example"],
    doc_md="""
    ### Facebook Marketing Example DAG
    A simple DAG demonstrating how to use the FacebookMarketingOperator to fetch ad accounts.
    Requires a 'facebook_marketing_default' Airflow connection with an access token.
    """
) as dag:
    get_ad_accounts = FacebookMarketingOperator(
        task_id="get_ad_accounts",
        facebook_conn_id="facebook_marketing_default",
        api_method="GET",
        api_path="/me/adaccounts",
        fields=["id", "name", "account_status"],
        result_processor=lambda result: print(f"Fetched Ad Accounts: {result}")
    )

view raw JSON →