Skip to content

Social Network Analyzer is a Flask-powered app that combines AI-driven insights with social media links (e.g., Twitter, Instagram). Validate profiles, add user context, and receive intelligent personality summaries via OpenAI’s cutting-edge models. Perfect for exploring the power of AI in an interactive way!

License

Notifications You must be signed in to change notification settings

VictoKu1/Social-Network-Analyzer

Repository files navigation

Social Network Analyzer

Pylint

This repository contains a Flask-based web application that lets users:

  1. Specify how many social network links they want to analyze.
  2. Enter and validate each link (Twitter, Instagram, Facebook, Threads, etc.).
  3. Provide a personal description about the person whose profiles are being analyzed.
  4. Analyze all collected data (links + description) via the OpenAI API to generate a personality overview or short psychological summary.

IMPORTANT DISCLAIMER

  • This is not a clinical or professional psychological tool.
  • The output can contain errors or "hallucinations" typical of Large Language Models.
  • Always comply with each social platform's terms of service regarding data collection/scraping.
  • Handle personal data with caution and respect user privacy.

πŸš€ New Features: Platform-Specific API Integration

The application now includes advanced platform-specific API integration for reliable social media data fetching:

βœ… Supported Platforms

  • Twitter/X: Full API v2 and v1.1 support with rate limiting
  • LinkedIn: Profile data extraction with authentication
  • Instagram: Public and private profile access via instaloader
  • Facebook: Graph API integration for profile data
  • Reddit: User data and post history via PRAW
  • Generic Platforms: Web scraping fallback for other platforms

πŸ”§ Key Improvements

  • Rate Limiting: Automatic API rate limit management
  • Authentication: OAuth and API key support for each platform
  • Fallback Mechanisms: Web scraping when APIs are unavailable
  • Structured Data: Consistent data format across all platforms
  • Error Handling: Comprehensive error handling and recovery

πŸ“Š Enhanced Data Extraction

  • Profile information (name, bio, location, website)
  • Follower/following counts
  • Verification status
  • Recent posts and activity
  • Account creation dates
  • Profile pictures

For detailed setup instructions, see API_INTEGRATION_GUIDE.md.


Features

  • Multi-Step Flow

    • Step A: Select the number of social network links.
    • Step B: Enter each link, then validate it against known social platforms.
      • If all links are valid, you can continue. Otherwise, you must correct them.
    • Step C: Provide a personal description for additional context.
    • Analysis: The server combines the links + personal description into a prompt, sends it to OpenAI, and displays a final summary.
  • Dynamic Frontend

    • Uses JavaScript (Fetch API) to handle link validation and multi-step UI.
    • Displays βœ“ for valid links and βœ— for invalid links.
  • OpenAI Integration

    • A sample prompt demonstrates how to create a short "personality analysis."
    • Requires an OpenAI API key (set in .env or as an environment variable).
  • Platform-Specific API Integration

    • Reliable data fetching using official APIs where available
    • Automatic fallback to web scraping for unsupported platforms
    • Rate limiting and error handling for robust operation

Quickstart

  1. Clone the Repository:

    git clone https://github.com/VictoKu1/Social-Network-Analyzer.git
    cd Social-Network-Analyzer
    
  2. Install Dependencies:

    • Python 3.8+ recommended.
    • Install packages:
    pip install -r requirements.txt
    
  3. Set Your API Keys:

    Create a .env file with your API credentials:

    # Required: OpenAI API
    OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx
    
    # Optional: Platform-specific APIs (see config_example.py for details)
    TWITTER_BEARER_TOKEN=your_twitter_bearer_token
    LINKEDIN_EMAIL=your_linkedin_email
    LINKEDIN_PASSWORD=your_linkedin_password
    INSTAGRAM_USERNAME=your_instagram_username
    INSTAGRAM_PASSWORD=your_instagram_password
    FACEBOOK_ACCESS_TOKEN=your_facebook_access_token
    REDDIT_CLIENT_ID=your_reddit_client_id
    REDDIT_CLIENT_SECRET=your_reddit_client_secret

    Note: Only the OpenAI API key is required. Platform-specific APIs are optional and will fall back to web scraping if not provided.

  4. Run the Flask App:

    python app.py
    
  5. Open Your Browser:

Visit http://127.0.0.1:5000/ to access the web app.

  1. Test the API Integration (Optional):

    python test_api_integration.py
    

Usage

  1. Step A: Select the number of social profiles (e.g., 2).
  2. Step B: Enter each URL in the generated fields (e.g., https://x.com/example), then click Validate Links.
  • If a link is marked βœ—, correct it.
  • If all links are βœ“, the Continue button appears.
  1. Step C: Provide a personal description for context (e.g., "She is very outgoing and enjoys discussing tech trends.").
  2. Click Analyze: The server sends the data to OpenAI and displays a final summary.

The application will now use platform-specific APIs when available, providing more reliable and comprehensive data extraction.


Project Structure

.
β”œβ”€β”€ static/             
β”‚   └── css/
β”‚       └── style.css    # CSS for the multi-step form
β”œβ”€β”€ js/                 
β”‚   └── app.js          # JavaScript for the multi-step form
β”œβ”€β”€ templates/
β”‚   └── index.html      # Implements the multi-step form using JavaScript
β”œβ”€β”€ app.py              # Main Flask app with routes
β”œβ”€β”€ analyze.py          # OpenAI-related analysis logic (link validation, prompt construction)
β”œβ”€β”€ social_media_fetchers.py  # NEW: Platform-specific API integration
β”œβ”€β”€ test_analyze.py     # Unit tests for the analyze.py logic
β”œβ”€β”€ test_api_integration.py   # NEW: API integration tests
β”œβ”€β”€ config_example.py   # NEW: Example configuration file
β”œβ”€β”€ API_INTEGRATION_GUIDE.md  # NEW: Comprehensive API setup guide
β”œβ”€β”€ requirements.txt    # Python package dependencies
β”œβ”€β”€ README.md           # This README file
β”œβ”€β”€ LICENSE             # License (MIT)
└── .gitignore          # Prevents committing unwanted files
  • app.py:

    • Defines the Flask routes:
      • GET / serves the main page (index.html)
      • POST /validate_links checks if each link is a recognized social network
      • POST /analyze calls the analysis function in analyze.py and returns the result
  • analyze.py:

    • Contains the core OpenAI analysis logic:
      • validate_social_link(link) checks if a URL is recognized (Twitter, Instagram, etc.).
      • analyze_personality(links_info, personal_description) constructs a prompt and calls the OpenAI API.
      • Updated to use platform-specific fetchers for better data extraction.
  • social_media_fetchers.py: NEW

    • Platform-specific API integration for Twitter, LinkedIn, Instagram, Facebook, and Reddit
    • Rate limiting and error handling
    • Fallback mechanisms for unsupported platforms
    • Structured data extraction and formatting
  • test_analyze.py:

    • Contains unit tests for functions in analyze.py.
    • Uses Python's built-in unittest or can be adapted for pytest.
  • test_api_integration.py: NEW

    • Tests for the platform-specific API integration
    • Demonstrates the difference between old and new fetching methods
    • Validates rate limiting and error handling
  • config_example.py: NEW

    • Example configuration file showing all required API credentials
    • Detailed setup instructions for each platform
    • Security best practices
  • API_INTEGRATION_GUIDE.md: NEW

    • Comprehensive guide for setting up platform-specific APIs
    • Troubleshooting and performance optimization tips
    • Security considerations and best practices
  • Templates/index.html:

    • Implements the multi-step form using JavaScript.
    • Uses the Fetch API to call /validate_links and /analyze.
  • requirements.txt:

    • Python package dependencies.
    • Updated to include platform-specific API libraries.
  • .gitignore:

    • Hides temporary or sensitive files (e.g., venv/, .env, __pycache__, etc.) from version control.

Testing

To run the unit tests for analyze.py, use one of the following:

Using Python's built-in unittest

python -m unittest discover

or specifically:

python -m unittest test_analyze.py

Using pytest (if installed)

pytest

Testing API Integration (NEW)

python test_api_integration.py

Tests in test_analyze.py:

  • Mock the OpenAI API to avoid real API calls.
  • Verify that functions like validate_social_link and analyze_personality behave as expected.

Tests in test_api_integration.py:

  • Compare old generic fetching with new platform-specific fetching
  • Validate rate limiting and error handling
  • Test platform detection and username extraction
  • Verify fallback mechanisms work correctly

API Setup

For detailed instructions on setting up platform-specific APIs, see API_INTEGRATION_GUIDE.md.

Quick Setup Summary

  1. Twitter/X: Get API keys from Twitter Developer Portal
  2. LinkedIn: Use email/password (not recommended for production)
  3. Instagram: Use username/password for private profiles
  4. Facebook: Get access token from Facebook Developers
  5. Reddit: Create app at Reddit App Preferences

Security Notes

  • Never commit API keys to version control
  • Use environment variables for sensitive data
  • Regularly rotate your API keys
  • Monitor API usage to avoid rate limits

Contributing

  1. Fork this repo and clone your fork.
  2. Create a new branch for your feature/bugfix:
git checkout -b feature/new-stuff
  1. Commit and push your changes:
git commit -m "Add new feature"
git push origin feature/new-stuff
  1. Open a Pull Request on GitHub.

License

Please see the LICENSE file for details.

Disclaimer

  • This software is provided "as is," without any warranty or guarantee.
  • Always comply with social media platforms' terms of service and API usage policies.
  • Respect user privacy and data protection regulations.

About

Social Network Analyzer is a Flask-powered app that combines AI-driven insights with social media links (e.g., Twitter, Instagram). Validate profiles, add user context, and receive intelligent personality summaries via OpenAI’s cutting-edge models. Perfect for exploring the power of AI in an interactive way!

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published