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,
},
)
# NOTE: You should more securely handle the access token in production
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
Release history Release notifications | RSS feed
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.1.tar.gz
(7.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
vroid-0.1.1-py3-none-any.whl
(10.0 kB
view details)
File details
Details for the file vroid-0.1.1.tar.gz.
File metadata
- Download URL: vroid-0.1.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a93c66b63356d5e572ae551b414e54c9000bedf8fb90bc78e3d2415f863d2f59
|
|
| MD5 |
e764bcd3da0506dd0c10c5fde3d7bf24
|
|
| BLAKE2b-256 |
9e535a97b341f5da3a4b7880c9bd1724a01df697f3fa2cdc8d4e7331e3e25116
|
File details
Details for the file vroid-0.1.1-py3-none-any.whl.
File metadata
- Download URL: vroid-0.1.1-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7dfd0c626e535fadfc5ce9b05cd3e3618f3700aec0f2eabf0da015aa3cc1818f
|
|
| MD5 |
23c29d12c92dae61c4a6719a8d5ec98a
|
|
| BLAKE2b-256 |
6f99cb402f46bba24b475ffe85b8ea2bcc3aeba275be760ce73af31c2e468e5d
|