Bilibili Triple-Action Ads - Authorization and Main Flow: Unified Entry for Triple-Action MAPI and OAuth Scheduling

Preface

When connecting to Bilibili Sanlian ads via MAPI using an Agent, a common approach is to let the model directly construct curl commands or hand-write HTTP requests: firing multiple parallel requests across accounts, embedding access_token in command lines, or modifying ads before clarifying account scope. The Sanlian side applies shared quotas to client_id, and the legacy three-layer (campaign/ad group/creative) and the materialized 2.0 (project/creative) APIs do not interoperate. The following describes the Bilibili Sanlian Ads - Authorization & Main Workflow (internal name bilibili-sanlian-ads) on SkillHub: officially positioned as the Start-here entry point for any Sanlian ad task, it first performs intent clarification and authorization, then routes the task to sub-Skills for delivery, creative materials, reports, etc.

What is this

In one sentence: A guide for global authorization, invocation discipline, and task routing for Bilibili Sanlian Ads MAPI.

  • Display name: Bilibili Sanlian Ads - Authorization & Main Workflow
  • Package identifier: slug: sanlian-ads, name: bilibili-sanlian-ads
  • Maintainer: SKILL metadata author is Benjamin, MIT license; current package version 3.0.4
  • Distribution: SkillHub category business-ops (page stats: rating 98707, downloads 687)
  • Official page: https://api.skillhub.cn/user_b0010d5c/sanlian-ads

It does not cover the full set of specific creation fields (those live in each sub-Skill’s references/, sourced from the Bilibili Open Platform MAPI docs). Instead, it solves: “do I have a token, which account_id is managed, should I use v3 or v4, which Skill to open next.”

Core Features

All capabilities below come from the Skill’s SKILL.md documentation.

Non-technical interaction for operators

  • Clarify intent in plain Chinese; do not throw JSON, curl, or local credential paths at the user.
  • For operations that may have online impact, first compile an operation brief (account, account_id, read/write, object hierarchy, time range, etc.), and follow phased confirmation before writing (intent confirmation → execution confirmation → canary and batch checkpoints for multi-object operations).
  • Details in references/operator-interaction-and-confirmation.md within the package.

OAuth 2.0 and token lifecycle

  • Authorization URL, state validation, authorization code exchange, and refresh are handled through the bundled client; access_token is valid for 24 hours, refresh_token for 30 days (successful refresh resets the 30-day window).
  • The local credential file is managed by scripts/mapi_client.py: fixed paths per OS, 0700/0600 permissions, atomic writes, cross-process locks; the environment variable BILIBILI_MAPI_CREDENTIALS can override the default path.
  • Supports querying authorized users, principals, delivery accounts, and account details; multiple authorization records are merged or stored separately by account scope.
  • OAuth and business API reference indices are in references/1846_开发者完整接入指南.md etc.

Conservative MAPI invocation discipline (shared quota)

  • No concurrency: At most one MAPI request in flight globally at any time; the minimum interval between adjacent requests is about 1 second (client-enforced floor, not representing the platform quota limit).
  • Rate-limit errors should stop immediately; read-only transient failures can be retried with backoff at most once; when write results are unknown, blind retries are forbidden—only documented query-back reads are allowed.
  • Each request must carry X-Call-Source: sanlian-skills and X-Sanlian-Skills-Version: 3.0.4; the business root domain is https://cm.bilibili.com/takumi/api, and Authorization: Bearer {access_token} along with account_id are required.
  • HTTP 200 may still contain business failures; check the corresponding references/ for the success shape (code: 0, code: 200, or status: "success", etc.).

Legacy vs 2.0 routing

Structure API Sub-Skill
Campaign → Ad Group → Creative (v3) /open_api/cpc/v3/* bilibili-sanlian-ads-ad-management
Project → Creative Material (v4, whitelist by invitation) /open_api/cpc/v4/* bilibili-sanlian-ads-delivery

The two data models and ID spaces are isolated and cannot read or write each other; whitelisted accounts can only create new ads via 2.0, while existing legacy ads are still managed via v3. When unsure about whitelist status, after obtaining a token and account_id, probe with GET /open_api/cpc/v4/promotion/list, distinguishing between 401 and business-level rejection.

Task routing

User Goal Sub-Skill
Authorization, tokens, account scope (this Skill) bilibili-sanlian-ads
2.0 project/creative material creation bilibili-sanlian-ads-delivery
Legacy campaign/ad group/creative bilibili-sanlian-ads-ad-management
Pre-save optional enumeration, targeting, resource queries bilibili-sanlian-ads-metadata
Image/video materials bilibili-sanlian-ads-materials
Org-level assets, conversion components, etc. bilibili-sanlian-ads-assets
Delivery reports bilibili-sanlian-ads-reporting
Account budgets, wallets, transactions bilibili-sanlian-ads-account-finance
RTA strategies bilibili-sanlian-ads-rta

On errors, follow references/error-triage-and-handoff.md for cold re-checks and support info compilation.

Chinese trigger words (for invoking in an Agent): B站广告, 哔哩哔哩广告, bilibili 广告, 三连, 三连投放, MAPI, 开放平台, 广告 API, 授权, 开发者, client_id, access_token, 令牌, 接入.

Installation and Activation

Obtaining from SkillHub

Open the official page in a browser and install/import to the current Agent environment (specific buttons depend on the SkillHub page):

https://api.skillhub.cn/user_b0010d5c/sanlian-ads

Sanlian ads is a set of collaborative Skills: in WorkBuddy scenarios, the documentation requires importing the complete Sanlian OAuth skill package (including the entry Skill and related domain Skills). Do not make requests to live accounts when packages are missing. WorkBuddy operation path is in references/workbuddy-getting-started.md within the package (“Expert · Skills · Connectors” → upload skill); Tencent Cloud WorkBuddy skill documentation: https://cloud.tencent.com/document/product/1831/134432 .

For Cursor, Codex CLI, Claude Code installation commands, since product integration methods differ, no unified CLI statement was captured on the official page; do not fabricate here; defer to the SkillHub page and each product’s Skill import capability.

Runtime dependencies

  • Python 3.8+, standard library only (no third-party dependencies).
  • macOS / Linux use scripts/mapi.sh; Windows uses py -3 scripts/mapi_client.py with equivalent subcommands. If the executable bit is lost, use sh scripts/mapi.sh ....
  • Optional environment variables: SANLIAN_PYTHON (specify interpreter), BILIBILI_MAPI_CLIENT_SECRET (provide secret outside stdin when exchanging tokens), BILIBILI_MAPI_CREDENTIALS (credential file path).

Default credential paths (excerpt):

macOS:   ~/Library/Application Support/bilibili-sanlian-ads/credentials.json
Windows: %LOCALAPPDATA%\bilibili-sanlian-ads\credentials.json
Linux:   ${XDG_CONFIG_HOME:-~/.config}/bilibili-sanlian-ads/credentials.json

Developer client_id / client_secret require completing qualification and app creation at https://ad.bilibili.com/developer/onboard (the Skill notes that sales/operations assistance is needed to advance MAPI review, with a cycle of about three working days).

Typical Usage

  1. First run scripts/mapi.sh token-status; do not ask the user for keys immediately.
  2. When no usable token exists (exit code 60), collect client_id, client_secret, and proceed with OAuth.
  3. Query principal and delivery accounts, confirm account_id before writing operations.
  4. Determine legacy or 2.0, then open the corresponding sub-Skill and its references/.

OAuth and probe commands

Execute in the Skill package root directory (on Windows, replace the prefix with py -3 scripts/mapi_client.py):

scripts/mapi.sh doctor
scripts/mapi.sh auth-url <client_id>
scripts/mapi.sh auth-exchange "<full callback URL>"
scripts/mapi.sh token-status
scripts/mapi.sh token-refresh
scripts/mapi.sh call GET  <path> [--query-file q.json]
scripts/mapi.sh call POST <path> --body-file body.json

Authorization page form (generated by auth-url):

https://ad.bilibili.com/developer/developer-authorization?client_id={client_id}&state={state}

The user copies the full callback URL from the browser address bar (e.g., https://sanlian.com?code=...&state=...) and passes it to auth-exchange; client_secret goes via stdin or BILIBILI_MAPI_CLIENT_SECRET, do not put it in command-line arguments.

call only accepts paths with the /open_api/ prefix; non-MAPI requests (such as public draft queries, presigned uploads) must not go through this client.

End-to-end example (workflow summary in documentation)

Check spend (read-only)

  1. This Skill: token and account scope.
  2. bilibili-sanlian-ads-reporting: custom report.
  3. Only use bilibili-sanlian-ads-account-finance when the user asks about balance, budget, or transactions.

Create ad (legacy)

  1. This Skill: operation brief, account confirmation.
  2. bilibili-sanlian-ads-metadata: pull optional values per creation-field-source-map.md.
  3. bilibili-sanlian-ads-materials: prepare materials.
  4. bilibili-sanlian-ads-ad-management: campaign → ad group → creative, verify via query after each write step.

Create ad (2.0 whitelist account)

  1. This Skill: confirm whitelist and intent.
  2. metadata → bilibili-sanlian-ads-delivery (project, material, binding), confirm boundaries for each write operation separately.

Operator-side colloquial examples (from WorkBuddy getting-started guide): “Query account 123456 yesterday’s spend, impressions, clicks, and conversions” / “List account 123456’s current running projects, query only, no modifications”.

Applicable Scenarios and Notes

Who it’s for

  • Developers or delivery operators who need stable MAPI integration for Sanlian ads in an Agent (especially scenarios where the model shouldn’t hand-write HTTP).
  • Scenarios where tasks span multiple modules like authorization, creation, materials, reports, finance, RTA, etc., and need a fixed routing table.

Limitations and pitfalls

  • Do not operate live accounts with only the entry Skill installed; if a sub-Skill or references/ is missing, stop and complete the package.
  • Do not write credentials in the Skill directory, project repository, or cloud-synced folders; do not echo tokens or full callback URLs in conversations.
  • Product management, agency management, account qualifications, incentive coupons, conversion callback protocols, etc., are not covered by this skill set; point to official documentation or business coordination.
  • After modifying scripts/mapi_client.py, run scripts/mapi-test.sh for local regression (no network, no real credentials).

Conclusion

Bilibili Sanlian Ads - Authorization & Main Workflow consolidates OAuth, account scope, invocation order, and sub-Skill routing into a single entry point, so subsequent creation and reporting execute under the same set of security constraints. For any Sanlian ad-related task, it’s recommended to load this Skill first, then route into domain packages.

Official address: https://api.skillhub.cn/user_b0010d5c/sanlian-ads

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye