Primary repository for workflow automation and educational Twitter & Facebook API integration
A comprehensive Python-based automation tool designed for educational purposes, enabling users to learn Twitter and Facebook API integration, data analysis, sentiment tracking, and automated content generation (using Google Gemini API) while adhering to platform policies.
- π Prodigal Automation
- π Running Your First Example
- π¦ Twitter API Integration β Seamless connection with Twitter API v2
- π Facebook Graph API Integration β Post text, images, videos, and retrieve insights
- π€ Gemini API Integration β Smart, AI-powered content generation with Google Gemini
- π Data Analysis β Comprehensive tweet/post data collection and analysis
- π Sentiment Analysis β Real-time sentiment tracking and monitoring
- π Trend Analysis β Explore trending topics and user interactions
- π Post Scheduling β Schedule content for future publication on Facebook
- π§ Multi-tenant Support β Handle multiple social media accounts
- π‘οΈ Security First β Secure token management and authentication
- π Educational Focus β Designed for learning and skill development
prodigal-automation/
βββ .github/ # βοΈ GitHub-specific configuration (CI/CD)
β βββ workflows/ # π€ GitHub Actions workflows
β βββ ci.yml # π§ͺ CI pipeline definition
βββ src/
β βββ prodigal_automation/
β βββ examples/ # π‘ Example scripts (see below)
β β βββ twitter_example.py # π¦ Single-account Twitter automation
β β βββ twitter_multi_tenant.py # π₯ Multi-account setup
β β βββ facebook_example.py # π Facebook automation examples
β βββ tool_modules/ # π§© Modular tool integrations (Twitter, LinkedIn, etc.)
β βββ auth.py # π Handles authentication
β βββ client.py # π API client interface for Twitter & Facebook
β βββ facebook.py # π High-level Facebook automation logic
β βββ facebook_manager.py # πΉοΈ Facebook API interactions and content management
β βββ oauth.py # π OAuth flow handlers
β βββ tools.py # β¨ Content generation and validation
β βββ twitter_manager.py # πΉοΈ High-level Twitter logic
β βββ twitter.py # π οΈ Twitter utilities and helpers
βββ tests/ # π§ͺ Test suite (unit/integration tests)
β βββ test_client.py # Tests for client.py (including FacebookClient)
β βββ test_facebook_manager.py # Tests for facebook_manager.py
βββ .gitignore # π« Files and folders to ignore in Git
βββ CHANGELOG.md # π Project changelog/history
βββ https://www.google.com/search?q=CODE_OF_CONDUCT.md # π€ Contributor Code of Conduct
βββ CONTRIBUTORS.md # π₯ List of project contributors
βββ https://www.google.com/search?q=CONTRIBUTING.md # π€οΈ Contributing guidelines
βββ https://www.google.com/search?q=LICENSE # π Project license (MIT)
βββ pyproject.toml # βοΈ Python project metadata/config
βββ README.md # π Project overview and instructions
βββ requirements.txt # π¦ Main dependencies
βββ requirements_dev.txt # π§βπ» Dev/testing dependencies
βββ TESTING.md # π§ͺ Testing instructions and details- Python: Version 3.12 (mandatory β create your venv with this version)
- Git: For cloning the repository
- Twitter Developer Account: Apply here
- Facebook Developer Account: Apply here
- Gemini API Key: For AI-powered content generation (see below)
-
Clone the Repository
git clone https://github.com/Prodigal-AI/prodigal-automation.git cd prodigal-automation -
Create a Python 3.12 Virtual Environment
IMPORTANT: The virtual environment must use Python 3.12.
If you have multiple Python versions, specify 3.12 when creating the venv.python3.12 -m venv prodigal_env source prodigal_env/bin/activate # On Windows: prodigal_env\Scripts\activate
To check the Python version in your venv:
python --version # Should print: Python 3.12.x -
Install Dependencies
pip install -r requirements.txt
-
Set Up Environment Variables
Copy the example
.envfile and edit it with your Twitter API credentials (instructions for getting these are below).
Note:
In addition to Twitter API keys, you should also add your Gemini API key in the.env.examplefile and your actual.env. This is required for Gemini-based features.cp src/prodigal_automation/examples/.env.example src/prodigal_automation/examples/.env # Edit src/prodigal_automation/examples/.env with your credentials # Add your Gemini API key as GEMINI_API_KEY=your_gemini_api_key
- Go to the Twitter Developer Portal
- Click "Sign up for Free Account"
- Accept the Developer Agreement & Policy
When prompted, paste this use-case description:
I plan to use the Twitter API strictly for educational purposes. My goal is to learn how to collect and analyze tweet data, perform sentiment analysis, explore trends, build small data science and NLP projects, and develop simple Twitter bots. This will help me gain hands-on experience in data analysis, machine learning, and API integration for academic and personal growth. I do not intend to use the data for commercial purposes or to violate Twitter's policies. The focus is on skill-building, research, and exploring real-time social media data to better understand user interactions, public sentiment, and event trends.
- Go to Projects & Apps β Select your project
- Click Edit and configure:
- App Name:
Prodigal Automation Testing(or your preferred name) - Description:
Educational use of Twitter API for data analysis, sentiment tracking, and building small NLP and bot projects to enhance programming and machine learning skills.
- App Name:
- Click Save
- Go to User Authentication Settings β Set up
- Set permissions:
- β Read and Write
- Type:
Web App, Automated App or Bot - Callback URI:
https://www.prodigalai.com/ - Website URL:
https://www.prodigalai.com/
- Click Save β Yes
- Keys and Tokens β Consumer Keys β Regenerate
- Authentication Tokens β Bearer Token β Regenerate
- Access Token and Secret β Regenerate
Store all credentials securely!
Youβll need them for the next step.
To enable Facebook automation, you'll need a Facebook Developer account, a Facebook App, and a Page Access Token with sufficient permissions for the Facebook Page you want to manage.
- Go to the Facebook for Developers Portal
- If you don't have one, click "Get Started" to create a new developer account.
- You'll need to verify your account.
- In the Facebook for Developers dashboard, click "Create App".
- Choose the app type (e.g., "Business" or "None" if you're just experimenting for learning).
- Provide an App Name (e.g., "Prodigal Automation App").
- Click "Create App".
This is the most critical part for posting to a Page.
- From your App Dashboard, under "Add a Product", find "Marketing API" or "Graph API" and click "Set Up".
- For simpler posting, you might not need the full Marketing API. Setting up a "Basic Display" or "Business" app and navigating to the Graph API Explorer is a common path.
- Go to Graph API Explorer.
- Select your newly created app from the Application dropdown.
- Click "Get Token" β "Get User Access Token".
- Select the required permissions (see Required Permissions below). This gives you a User Access Token.
- With the User Access Token selected, click "Get Token" again β "Get Page Access Token".
- Select the Facebook Page you manage and wish to post to. This will generate a Page Access Token.
Important:
- Copy this Page Access Token β itβs usually long-lived.
- While in the Graph API Explorer, you can also find your Facebook Page ID:
- Select the Page Access Token.
- In the dropdown for objects, select your page name.
- The ID will appear in the URL or response.
FACEBOOK_ACCESS_TOKEN=your_page_access_token
FACEBOOK_PAGE_ID=your_page_idpages_show_listpages_read_engagementpages_manage_postspages_manage_ads(sometimes needed for advanced scenarios)
read_insightspages_read_engagement
You need to select these permissions when generating your User Access Token in the Graph API Explorer, before exchanging it for a Page Access Token.
β οΈ Some permissions may require App Review for production use, but for development and learning, theyβre typically accessible.
Gemini is Google's new generative AI platform.
You need a valid Gemini API key to enable automated content generation in this project.
-
Go to the Google AI Studio
Google AI Studio -
Sign in with your Google account
- Use a personal or educational Google account.
-
Create a New API Key
- Click on "Create API Key"
- Assign a name (e.g., "Prodigal Automation")
- Click Create
-
Copy Your API Key
- Once generated, click the copy button.
-
Add Your API Key to the Project
- Open your
.envfile (see Installation Guide above) - Add the key:
GEMINI_API_KEY=your_gemini_api_key
- Open your
-
Keep Your Key Secure!
- Never share or commit your API key to public repositories.
Once you have your Twitter API credentials, Facebook API credentials, Gemini API key, and have set up your virtual environment with Python 3.12, follow these steps to run the sample script and automate content generation:
- Go to:
src/prodigal_automation/examples/ - Right-click on
twitter_example.pyorfacebook_example.pyand select "Open in Integrated Terminal" in your code editor (e.g., VS Code).
Note:
You are running*_example.pyβ not*.py(e.g.,twitter.pyorfacebook.py).
From the integrated terminal, run:
python twitter_example.py
# or for Facebook:
python facebook_example.pyThe script will interactively prompt you for the necessary credentials.
For "Topic", enter a subject you'd like to generate content about (e.g., AI and Machine Learning).
- Bearer Token
- API Key
- API Key Secret
- Access Token
- Access Token Secret
- Gemini API Key
- Topic (for content generation)
- Gemini API Key
- Facebook Page Access Token
- Facebook Page ID
- Facebook App ID (optional)
- Facebook App Secret (optional)
- Facebook post topic (for content generation)
Prompts for image/video URLs, scheduling, insights, or deletion are based on the script's interactive flow.
- The scripts will automatically generate content up to platform-specific limits (e.g., Twitter's 280-character limit).
- The content is optimized for both brevity and quality using the Gemini API.
- You can modify or extend scripts in
src/prodigal_automation/examples/for more advanced or multi-account use cases, including posting images/videos, scheduling posts, and retrieving insights on Facebook.
from prodigal_automation.twitter_manager import TwitterManager
import os
# It's recommended to load credentials from environment variables or a .env file
# For example, using python-dotenv:
# from dotenv import load_dotenv
# load_dotenv()
manager = TwitterManager(
bearer_token=os.getenv("TWITTER_BEARER_TOKEN"),
api_key=os.getenv("TWITTER_API_KEY"),
api_secret=os.getenv("TWITTER_API_SECRET"),
access_token=os.getenv("TWITTER_ACCESS_TOKEN"),
access_token_secret=os.getenv("TWITTER_ACCESS_TOKEN_SECRET"),
gemini_api_key=os.getenv("GEMINI_API_KEY")
)
result = manager.create_tweet(topic="AI and Machine Learning")
print(result)from prodigal_automation.facebook import FacebookAutomation
import os
# It's recommended to load credentials from environment variables or a .env file
# For example, using python-dotenv:
# from dotenv import load_dotenv
# load_dotenv()
# FacebookAutomation can initialize directly from environment variables
# if they are set (FACEBOOK_ACCESS_TOKEN, FACEBOOK_PAGE_ID, GEMINI_API_KEY)
fb_automation = FacebookAutomation()
# Example: Create a text post
post_result = fb_automation.facebook_manager.create_post(topic="Sustainable AI practices")
print(f"Text Post Result: {post_result}")
# Example: Post an image (requires an image URL)
image_url = "https://picsum.photos/1200/630" # Replace with a real image URL
image_post_result = fb_automation.facebook_manager.post_image(
message="Check out this beautiful image!",
image_url=image_url
)
print(f"Image Post Result: {image_post_result}")
# Example: Schedule a post for 1 hour from now
import time
scheduled_time = int(time.time()) + 3600 # 1 hour from now
scheduled_post_result = fb_automation.facebook_manager.create_post(
topic="The future of renewable energy",
scheduled_publish_time=scheduled_time
)
print(f"Scheduled Post Result: {scheduled_post_result}")
# Example: Get Page Insights (requires read_insights permission)
insights_result = fb_automation.facebook_manager.get_page_metrics(
metrics=['page_impressions_unique', 'page_post_engagements'],
period='week'
)
print(f"Page Insights: {insights_result}")To ensure the stability and correctness of the project, especially after making changes, it's highly recommended to run the test suite.
cd prodigal-automationpip install -r requirements_dev.txtpoetry run pytestThis command will discover and run all test files (e.g.,
test_client.py,test_facebook_manager.py) within thetests/directory.
You will see output indicating the number of tests run and whether they passed or failed.
We welcome contributions from everyone!
If you want to become a contributor, please make sure to read and follow:
- CONTRIBUTORS.md:
Meet the people behind this project and see how you can join the list! - CODE_OF_CONDUCT.md:
Strictly follow our Code of Conduct to maintain a welcoming, respectful, and inclusive community. - CONTRIBUTING.md:
Step-by-step guide for setting up your development environment, submitting PRs, reporting issues, and all collaboration rules.
New members must strictly follow the guidelines and steps outlined in
CONTRIBUTING.mdand adhere to ourCODE_OF_CONDUCT.mdat all times.
This project is licensed under the MIT License. See the LICENSE file for details.
See CONTRIBUTORS.md for the full list, or meet a few of our awesome contributors below!
See CHANGELOG.md for a detailed history of changes and updates.
β Star this repository if you find it helpful!
Report Bug β’ Request Feature β’ Documentation
Built with β€οΈ for educational purposes and the developer community