Bilibili Comments and Danmaku API: BVID, AID and CID
Use JustOneAPI to request Bilibili video details, ordinary comments and danmaku with the right identifiers. Separate cursor and page inputs and save up to three response snapshots.
Start with a BVID, then prepare the identifiers for comments
JustOneAPI Bilibili Video Details V2 accepts bvid, ordinary Video Comments V2 accepts aid, and Video Danmaku V2 accepts both aid and cid. Confirm that these identifiers refer to the same video and the intended part before making the separate requests.
Ordinary comments are discussions in the video's comment section. Danmaku is text associated with playback time. A comment count or danmaku count in video metadata is a statistic, rather than the underlying text. This guide saves responses from up to three requests so you can inspect the actual data before building an internal analysis workflow.
Which identifiers does each endpoint require?
- Video Details V2:
GET /api/bilibili/get-video-detail/v2; requirestokenandbvid. - Video Comments V2:
GET /api/bilibili/get-video-comment/v2; requirestokenandaid, with an optionalcursor. - Video Danmaku V2:
GET /api/bilibili/get-video-danmu/v2; requirestoken,aidandcid, with an optionalpage.
BVID identifies the video, AID is the archive identifier, and CID is required here for the target video-part request. A full video URL is not a bvid value. Do not substitute a BVID for an AID or an AID for a CID. For a video with several parts, confirm the part you want and its corresponding CID.
If you only have a BVID, request details first and inspect the response to establish the AID and the target part's CID. The current public OpenAPI does not fix the internal data structure for these three endpoints. The code below therefore assumes no JSON path for those identifiers and performs no automatic BVID-to-AID conversion.
Comments use cursor; danmaku uses page
The optional pagination input for ordinary comments is cursor. The initial comments request below omits it. Before continuing, identify the next-cursor value and end condition in an actual response. A next_cursor, offset or page-number convention from a different endpoint is not sufficient evidence.
Danmaku has an optional page input. This example also omits it and saves one default request's response. The current parameter description does not specify the default page number, playback interval covered by a page, or total number of pages. A single response cannot establish coverage of an entire video or its historical danmaku.
Manage the two pagination flows separately. Before increasing coverage, verify each list location, stable record identifier and stopping condition, then set a request budget and deduplication rules. Request counts, saved-file counts and record counts measure different things.
Example: Save responses using identifiers you have checked
Get an API Token from the JustOneAPI dashboard. Check permissions, pricing and available trial requests for all three endpoints individually. Documentation establishes the request shape; actual retrieval also depends on account access, the selected video and current service availability.
These commands are for macOS or Linux. Set your Token and known BVID, then add AID and CID only after checking them. The script uses your inputs and does not verify that they belong to the same video.
python3 -m pip install requests
export JUSTONEAPI_TOKEN='your_token'
export BILIBILI_BVID='your_known_bvid'
# Optional: confirm the same video's AID before requesting comments.
# export BILIBILI_AID='your_verified_aid'
# Optional: confirm the target part's CID before requesting danmaku.
# export BILIBILI_CID='your_verified_cid'Save the code as bilibili_comments.py and run python3 bilibili_comments.py. BVID alone produces one details request. Setting AID adds one comments request; also setting CID adds one danmaku request. Each run makes at most three requests, without automatic pagination, retries or redirects.
import json
import os
from datetime import datetime, timezone
from pathlib import Path
import requests
BASE_URL = "https://api.justoneapi.com"
TOKEN = os.environ.get("JUSTONEAPI_TOKEN", "").strip()
BVID = os.environ.get("BILIBILI_BVID", "").strip()
AID = os.environ.get("BILIBILI_AID", "").strip()
CID = os.environ.get("BILIBILI_CID", "").strip()
def call_api(path, params):
try:
response = requests.get(
BASE_URL + path,
params={"token": TOKEN, **params},
timeout=120,
allow_redirects=False,
)
except requests.RequestException:
raise RuntimeError("API network error or timeout") from None
if response.status_code != 200:
raise RuntimeError(f"API HTTP {response.status_code}")
try:
result = response.json()
except ValueError:
raise RuntimeError("API response is not JSON") from None
if not isinstance(result, dict):
raise RuntimeError("Unexpected API response")
if type(result.get("code")) is not int or result["code"] != 0:
raise RuntimeError("API business failure; check the docs and account")
if "data" not in result:
raise RuntimeError("Missing data; inspect the current docs")
return {key: value for key, value in result.items() if key != "requestParams"}
def save_snapshot(folder, name, path, params):
result = call_api(path, params)
snapshot = {
"capturedAtUTC": datetime.now(timezone.utc).isoformat(),
"endpoint": path,
"request": params,
"response": result,
}
(folder / name).write_text(
json.dumps(snapshot, ensure_ascii=False, indent=2), encoding="utf-8"
)
print(f"Saved {name}")
def main():
if not TOKEN or TOKEN == "your_token" or not BVID:
raise RuntimeError("Set JUSTONEAPI_TOKEN and BILIBILI_BVID")
if CID and not AID:
raise RuntimeError("Set a verified BILIBILI_AID before using BILIBILI_CID")
run_id = datetime.now(timezone.utc).strftime("%Y%m%dT%H%M%S%fZ")
folder = Path("bilibili-comments-output") / run_id
folder.mkdir(parents=True, exist_ok=False)
save_snapshot(
folder, "video-detail.json", "/api/bilibili/get-video-detail/v2",
{"bvid": BVID},
)
if AID:
save_snapshot(
folder, "comments-response.json", "/api/bilibili/get-video-comment/v2",
{"aid": AID},
)
if CID:
save_snapshot(
folder, "danmaku-response.json", "/api/bilibili/get-video-danmu/v2",
{"aid": AID, "cid": CID},
)
if __name__ == "__main__":
try:
main()
except RuntimeError as error:
raise SystemExit(str(error)) from NoneEach run creates a timestamped directory under bilibili-comments-output. The files separately hold details, comments and danmaku responses. A file is created only when the required identifiers are configured and that request succeeds. Files already saved remain available if a subsequent request fails.
After HTTP 200, the code checks for business code=0 and a data field. The exporter omits the top-level echoed requestParams and excludes the Token from its own request metadata, while preserving data without mapping it. These are response snapshots, rather than normalized comment tables or fully redacted exports. Inspect actual contents before sharing them.
Prepare the data for internal analysis
Verify the list location, text, time fields and stable identifiers for comments and danmaku separately. A comment's publication time and a danmaku message's playback position are different concepts; establish their meanings before combining records.
Keep BVID, AID, CID, endpoint version, capture time and requested pagination scope when comparing videos or parts. Distinguish failed retrieval, unknown response structure and a verified empty result. A request failure should not become “zero comments,” and a sample's proportions should not represent every viewer.
Frequently asked questions
Can one endpoint return both ordinary comments and danmaku?
These are separate endpoints. Comments requires AID; danmaku requires AID and CID. Request, save and paginate each according to your analysis goal.
Does the comments endpoint return every nested reply?
The current public contract does not establish complete nested-reply coverage or a reply-tree schema. Inspect an actual response first. A few included replies would not establish that the whole discussion thread was retrieved.
Which workflow should I use for subtitles?
Subtitles follow a separate workflow described in the video search, details and subtitle tutorial. Ordinary comments and danmaku responses do not replace subtitle tracks or speech transcription.
Open the Video Details documentation, check the identifiers and response for a familiar video within your account permissions and budget, then choose whether to analyze comments, danmaku or subtitles.
Continue with JustOneAPI
Log in to the Dashboard for your token, read the full API docs, or open the MCP GitHub project for the latest configuration.