Skip to main content

VRoid web api wrapper

Project description

VRoid Web API Python Wrapper

Example Usage

from sanic import Request, Sanic, json, redirect
from vroid import VRoid, VRoidOAuth

app = Sanic("VRoidApp")


@app.before_server_start
async def setup_vroid_oauth(app: Sanic, _):
    # Initialize VRoidOAuth with your client ID, secret, and redirect URI
    app.ctx.vroid_oauth = await VRoidOAuth.create(
        client_id="your_client_id_here",
        client_secret="your_client_secret_here",
        redirect_uri="http://localhost:8000/redirect",
    )


@app.route("/")
async def redirect_handler(request: Request):
    # Handle the redirect from VRoid OAuth
    url = request.app.ctx.vroid_oauth.request_to_initiate_authorization(
        response_type="code", scope="default"
    )
    return redirect(url)


@app.route("/redirect")
async def handle_redirect(request: Request):
    # Handle the redirect after authorization
    code = request.args.get("code")
    if not code:
        return json({"error": "Authorization code not provided"}, status=400)

    try:
        access_token_response = await request.app.ctx.vroid_oauth.request_access_token(
            code=code, grant_type="authorization_code"
        )
        access_token = access_token_response["access_token"]
        res = json(
            {
                "message": "Access token received successfully",
                "access_token": access_token,
            },
        )
        res.cookies.add_cookie(
            "access_token",
            access_token,
            max_age=3600,
            httponly=True,
        )
        return res
    except Exception as e:
        return json({"error": str(e)}, status=500)


@app.route("/character_models")
async def list_character_models(request: Request):
    access_token = request.cookies.get("access_token")
    if not access_token:
        return json({"error": "Access token not found"}, status=401)

    async with VRoid(access_token) as vroid:
        try:
            character_models = await vroid.list_of_character_models_posted_by_the_user()
            return json(character_models)
        except Exception as e:
            return json({"error": str(e)}, status=500)


@app.route("/revoke")
async def revoke_access_token(request: Request):
    access_token = request.cookies.get("access_token")
    if not access_token:
        return json({"error": "Access token not found"}, status=401)

    await app.ctx.vroid_oauth.revoke_access_token(token=access_token)
    return json({"message": "Access token revoked successfully"})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vroid-0.1.0.tar.gz (7.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vroid-0.1.0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file vroid-0.1.0.tar.gz.

File metadata

  • Download URL: vroid-0.1.0.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for vroid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bc8ff02644954b4bf233265ef47f2c49fb6e46b7a93cbde8246a432bc9f9b67d
MD5 d5ca32530ab5dc6cef74a3d173f4a3ab
BLAKE2b-256 36015a795aefbcfcd720f797865bf129fafb096389c2c158311d1a7877516b74

See more details on using hashes here.

File details

Details for the file vroid-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vroid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for vroid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7c5d7f90631afc0df936fdb966a7147d6496fd721c010106105f2a0e658903ee
MD5 d5a9de568bb44e6510db65bb3bc504ab
BLAKE2b-256 a6093386dc4f882bbafcce8f85a642b11b2fc434a20a0c7e081d6ce6ac76f257

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page