This is the global entry point for Bilibili Sanlian Ads MAPI. Use it first to understand the overall workflow, obtain or load authorization data, resolve the operable advertiser account scope, and then route the concrete task to a domain skill. Endpoint-level field details live in each skill's references/ files.
| User goal | Use this skill |
|---|---|
| --- | --- |
| Load token, refresh token, start OAuth authorization, query authorized user/subjects/accounts | bilibili-sanlian-ads |
| Account budget, wallet balance, daily budget, next-day budget, account cash flow | bilibili-sanlian-ads-account-finance |
| Campaign/unit/creative save, update, detail/list query, creative preview/audit verification | bilibili-sanlian-ads-ad-management |
| Promotion-purpose metadata, unit metadata, targeting options, creative resource lookup, and one-click acceleration | bilibili-sanlian-ads-metadata |
| Delivery reports, spend, impressions, clicks, conversions, daily/hourly metrics | bilibili-sanlian-ads-reporting |
| Batch campaign/unit/creative updates, batch task status, and batch task details | bilibili-sanlian-ads-batch-operations |
| Image upload/import, video signed URL upload, archive/submitted video creation, material tags | bilibili-sanlian-ads-materials |
All MAPI calls require an access_token. Tokens are generated through OAuth 2.0 authorization. Every new authorization can produce a new access_token and refresh_token; the token's authorization scope determines which Sanlian advertiser accounts can be managed.
A user may authorize multiple times. After each authorization, query the authorized user, authorized subjects, and advertiser accounts, then compare the new token's account scope with stored records. If the scope is the same as a previous authorization, use the new authorization data to replace the older token/refresh token record. If the scope differs, keep the records separate so future tasks can choose the correct account range.
Persist user-provided and API-returned authorization data in a secure local path. After the skill is installed and initialized for the first time, update this skill's description file with the storage path. Future agents using this skill should read that path directly instead of rediscovering it or asking the user again.
Store at least:
client_idclient_secretaccess_tokenrefresh_tokenredirect_uriaccess_token_expires_at and refresh_token_expires_atNever print, commit, or expose secrets. Use timestamps to judge expiration and to choose the freshest usable authorization record.
Use this JSON shape so independent agents can interoperate:
{
"version": 1,
"updated_at": "2026-05-31T00:00:00Z",
"default_record_id": "sha256:...",
"records": [
{
"record_id": "sha256:...",
"client_id": "...",
"client_secret": "...",
"redirect_uri": "https://example.com/callback",
"scope": "...",
"access_token": "...",
"refresh_token": "...",
"access_token_expires_at": "2026-05-31T12:00:00Z",
"refresh_token_expires_at": "2026-06-30T12:00:00Z",
"authorized_user": {},
"subjects": [],
"advertiser_accounts": [],
"selected_account_ids": [],
"created_at": "2026-05-31T00:00:00Z",
"updated_at": "2026-05-31T00:00:00Z"
}
]
}
Generate record_id deterministically from client_id, authorized user ID when available, redirect_uri, sorted subject IDs, and sorted advertiser account IDs. Store all IDs as strings in the credential file to avoid integer precision loss in JavaScript-based agents. When replacing an older same-scope record, preserve created_at and update updated_at.
When updating the credential file, write to a temporary file in the same directory and then rename it over the old file so other agents never read a partially written JSON file.
Before any real advertiser operation:
access_token exists for the requested user/account scope, use it.access_token is expired but a valid refresh_token exists, refresh the token with grant_type=refresh_token, persist the new token values, and continue.refresh_token, or refresh fails, guide the user through the OAuth authorization flow below.account_id.Most business APIs use https://cm.bilibili.com/takumi/api as the root path and require Authorization: Bearer {access_token} plus account_id.
Every MAPI request made through this skill set must include the custom source header below, including OAuth, business API, MAPI upload APIs, reporting, and polling requests. Add it even when a reference cURL example omits it.
X-Call-Source: sanlian-skills
client_id and client_secret only if they are not already stored locally.https://ad.bilibili.com/developer/developer-authorization?client_id={client_id}&state={state}
https://example.com/callback?code=...&state=....code from the callback URL. Use the same callback URL without query or fragment as redirect_uri. If token exchange fails with a redirect URI mismatch, try the same callback URL with or without the trailing /; a missing or extra trailing slash may be the cause.code for access_token and refresh_token with application/x-www-form-urlencoded:curl --location --request POST 'https://cm.bilibili.com/takumi/api/open_api/oauth2/token' \
--header 'X-Call-Source: sanlian-skills' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'code={code}' \
--data-urlencode 'client_id={client_id}' \
--data-urlencode 'client_secret={client_secret}' \
--data-urlencode 'redirect_uri={redirect_uri}'
access_token is valid for 24 hours by default. refresh_token is valid for 30 days, and each successful refresh resets the 30-day validity.
Refresh with:
curl --location --request POST 'https://cm.bilibili.com/takumi/api/open_api/oauth2/token' \
--header 'X-Call-Source: sanlian-skills' \
--data-urlencode 'grant_type=refresh_token' \
--data-urlencode 'refresh_token={refresh_token}' \
--data-urlencode 'client_id={client_id}' \
--data-urlencode 'client_secret={client_secret}'
If refresh fails because authorization was revoked, expired, or the refresh token is invalid, restart OAuth authorization.
227014 (OAUTH_REDIRECT_URI_MISMATCH), ask for the exact callback URL configured in the developer app and restart authorization with that value.https://example.com/callback and https://example.com/callback/ may be treated as different callback URLs.subject_type=1 when available. If no subject_type=1 subject exists, other subject types may be used, but handle them cautiously because the account scope may be very large.bilibili-sanlian-ads: load or obtain token, query account scope, and select account.bilibili-sanlian-ads-metadata: query promotion purpose, unit metadata, targeting options, creative locations, and available resources as needed.bilibili-sanlian-ads-materials: upload or prepare image/video materials if needed.bilibili-sanlian-ads-ad-management: create campaign, then unit, then creative.bilibili-sanlian-ads-ad-management: query campaign/unit/creative to verify result.bilibili-sanlian-ads: load or obtain token and confirm account scope.bilibili-sanlian-ads-reporting: query custom report metrics.bilibili-sanlian-ads-account-finance only when the user asks about cash balance, wallet balance, account budget, fund changes, or cash flow.bilibili-sanlian-ads: load or obtain token and confirm account scope.bilibili-sanlian-ads-ad-management: query current objects first.bilibili-sanlian-ads-batch-operations: submit batch operation.bilibili-sanlian-ads-batch-operations: query task status and details.bilibili-sanlian-ads-ad-management: re-query affected objects if verification is needed.| Source document | Local reference | Endpoint summary |
|---|---|---|
| --- | --- | --- |
开始使用/md/1846_开发者完整接入指南.md | references/1846_开发者完整接入指南.md | OAuth integration guide: authorization URL and token lifecycle |
开始使用/md/1763_获取访问令牌.md | references/1763_获取访问令牌.md | Exchange authorization code for access token: POST /open_api/oauth2/token |
开始使用/md/1764_刷新访问令牌.md | references/1764_刷新访问令牌.md | Refresh access token: POST /open_api/oauth2/token |
开始使用/md/1809_获取授权User信息.md | references/1809_获取授权User信息.md | Get authorized user info: GET /open_api/oauth2/userinfo |
开始使用/md/1810_OAuth2_0错误码.md | references/1810_OAuth2_0错误码.md | OAuth error codes |
开始使用/md/1855_获取授权主体列表.md | references/1855_获取授权主体列表.md | List authorized subjects: GET /open_api/oauth2/subjects |
开始使用/md/1784_获取授权账户列表.md | references/1784_获取授权账户列表.md | List authorized advertiser accounts: GET /open_api/oauth2/advertisers |
开始使用/md/1861_获取账户详情.md | references/1861_获取账户详情.md | Get advertiser account details: GET /open_api/cpc/v3/account/account_info/get |
共 2 个版本