This project provides a Python client for interacting with the Meta (formerly Facebook) Graph API. It fetches insights and posts data from Facebook and Instagram, and upserts this data into a PostgreSQL database.
- Fetches Facebook Page and Post insights
- Fetches Instagram Account and Post insights
- Supports save results as local CSV file or upsert data into PostgreSQL using SQLAlchemy.
-
Clone the repository:
git clone <repository_url>
-
Navigate to the project directory:
cd meta_api_insights
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
# On Windows venv\Scripts\activate # On macOS/Linux source venv/bin/activate
-
Install the dependencies:
pip install -r requirements.txt
Run the script from the command line with the following parameters:
./main.py <script_type> <start_date> <end_date>
<script_type>
:facebook
orinstagram
<start_date>
and<end_date>
: Dates inYYYY-MM-DD
format
For example, to fetch data for Instagram from May 1, 2023, to May 10, 2023:
./main.py instagram 2023-05-01 2023-05-10
If running from an IDE, the script defaults to fetching Instagram data for the last 7 days.
Feel free to submit issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License.