Git Product home page Git Product logo

socialmediaapi's Introduction

# TanjaX API

This project is a Flask-based web API that retrieves random images from specified Dropbox folders and provides direct links to these images. The API uses Auth0 for authentication and authorization, ensuring that only authorized users can access the API.

## Features

- Authenticate with Auth0
- List and fetch random images from specified Dropbox folders
- Provide direct links to images
- Handle existing shared links and create new ones if necessary
- Cross-Origin Resource Sharing (CORS) enabled

## Prerequisites

- Python 3.x
- A Dropbox account and a Dropbox app
- Auth0 account

## Installation

1. **Clone the repository:**

   ```bash
   git clone https://github.com/your-username/tanjax-api.git
   cd tanjax-api
  1. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  2. Install the dependencies:

    pip install -r requirements.txt
  3. Create a .env file in the root directory and add the following environment variables:

    API_TITLE=Your API Title
    DROPBOX_TOKEN=your_dropbox_token
    DROPBOX_APP_KEY=your_dropbox_app_key
    DROPBOX_REFRESH_TOKEN=your_dropbox_refresh_token
    DROPBOX_FOLDER_PATH=/path/to/your/dropbox/folder
    DROPBOX_FOLDER_APPROVE=/path/to/approve/folder
    DROPBOX_FOLDER_DELETE=/path/to/delete/folder
    DROPBOX_FOLDER_REWORK=/path/to/rework/folder
    REACT_APP_AUTH0_DOMAIN=your-auth0-domain
    REACT_APP_AUTH0_CLIENT_ID=your-auth0-client-id
    REACT_APP_AUTH0_AUDIENCE=your-auth0-audience
    

Configuration

Dropbox

  1. Create a Dropbox app:

  2. Generate a Refresh Token:

    • Follow the Dropbox OAuth 2 guide to generate a refresh token.
    • Ensure the necessary permissions (scopes) are granted to access the files.

Auth0

  1. Create an Auth0 Application:

    • Go to the Auth0 Dashboard.
    • Create a new Single Page Application.
    • Get the DOMAIN, CLIENT_ID, and AUDIENCE.
  2. Update Application Settings:

    • Ensure your application is configured to use the created API.
    • Enable CORS for your application's URL.

Running the Application

  1. Run the Flask API:

    flask run
  2. Run the React Application:

    cd react-app
    npm install
    npm start

    Open your web browser and navigate to http://localhost:3000/.

Deployment

PythonAnywhere

  1. Set environment variables on PythonAnywhere:

    • Go to the "Web" tab on PythonAnywhere.
    • Find the "Environment Variables" section and set your environment variables.
  2. Restart your web app:

    • Ensure your changes take effect by restarting the web app from the "Web" tab.

Usage

  • Authenticate using Auth0.
  • Access the random image endpoint to get a direct link to a random image from Dropbox.
  • The API will handle existing shared links or create new ones as needed.

Endpoints

  • GET /: Returns the API title.
  • GET /image: Returns a random image URL from the specified Dropbox folder.

Logging

  • The API uses Python's built-in logging module to log important events and errors.

Contributing

  1. Fork the repository
  2. Create a new branch (git checkout -b feature-branch)
  3. Commit your changes (git commit -am 'Add new feature')
  4. Push to the branch (git push origin feature-branch)
  5. Create a new Pull Request

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

socialmediaapi's People

Contributors

dhirmadi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.