Skip to content

哔哩哔哩视频搜索 API (V2) ​

GET
接口健康状态
健康 可用 少量可用 基本不可用 暂无数据
正在加载健康状态…

按关键词搜索哔哩哔哩视频,支持基于页面的分页,并可按照综合排名、播放量、发布时间、弹幕数或收藏数排序。用于支持内容发现、话题研究或排名导向的搜索。

请求参数 ​

参数名位置类型必填默认值说明
tokenquerystring是-API 的访问令牌。
keywordquerystring是-搜索关键词。
pagequerystring否-用于分页的页码。
orderquerystring否general搜索结果排序标准。


可用值:

- general: 综合

- click: 最多播放

- pubdate: 最新发布

- dm: 最多弹幕

- stow: 最多收藏

代码示例 ​

bash
curl --max-time 120 -X GET 'https://api.justoneapi.com/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE'
text
我想使用 JustOneAPI 提供的“视频搜索 (V2)”接口。
接入地址: https://api.justoneapi.com。
接口路径: /api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE
接口地址: BASE_URL + /api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE
HTTP 方法: GET
身份验证: 在 URL 中传入 token 查询参数。
OpenAPI 定义: https://docs.justoneapi.com/openapi/bilibili/video-search-v2-zh.json

请求参数说明:
- token (query): API 的访问令牌。 (必填)
- keyword (query): 搜索关键词。 (必填)
- page (query): 用于分页的页码。
- order (query): 搜索结果排序标准。

可用值:
- `general`: 综合
- `click`: 最多播放
- `pubdate`: 最新发布
- `dm`: 最多弹幕
- `stow`: 最多收藏

返回格式: 请根据实际 Content-Type 安全处理 JSON 或文本响应。

响应处理与错误码:
1. 需通过返回体中的 "code" 字段判断业务结果(code 为 0 表示成功)。
2. 超时建议:建议将请求超时时间设置为 120 秒;如果 120 秒偏长,请至少设置为 60 秒,但可能会有少量请求因超时而未接收到结果。
3. 业务码说明:
   - 0: 成功
   - 100: Token 无效或已失效
   - 301: 采集失败,请重试
   - 302: 超出速率限制
   - 303: 超出每日配额
   - 400: 参数错误
   - 500: 内部服务器错误
   - 600: 权限不足
   - 601: 账户余额不足
   - 602: TOKEN 限额超限
4. code 601 表示账户共享余额不足。code 602 表示当前 API TOKEN 自身的累计消费上限已达到。TOKEN 限额不是资金划拨,多个 TOKEN 仍共享同一个账户余额。

请帮我用我擅长的编程语言写一个脚本来调用这个接口,并处理返回结果。
python
import requests

BASE_URL = "https://api.justoneapi.com"  # 由 OpenAPI servers 提供

url = BASE_URL + "/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE"
response = requests.get(url, timeout=120)
print(response.status_code)
if response.content:
    content_type = response.headers.get("content-type", "").lower()
    if "json" in content_type:
        try:
            print(response.json())
        except ValueError:
            print(response.text)
    elif content_type.startswith("text/") or "xml" in content_type or content_type.split(";", 1)[0].strip() in {"application/javascript", "application/x-www-form-urlencoded", "application/graphql"}:
        print(response.text)
    else:
        with open("response.bin", "wb") as output:
            output.write(response.content)
        print(f"Saved {len(response.content)} bytes to response.bin")
js
const BASE_URL = "https://api.justoneapi.com"; // 由 OpenAPI servers 提供
const url = BASE_URL + "/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE";

const response = await fetch(url, {
  method: "GET",
  signal: AbortSignal.timeout(120000)
});
console.log(response.status);
const responseBytes = await response.arrayBuffer();
if (responseBytes.byteLength) {
  const contentType = (response.headers.get("content-type") || "").toLowerCase();
  const mediaType = contentType.split(";", 1)[0].trim();
  const textual = contentType.startsWith("text/") || contentType.includes("json") || contentType.includes("xml") || ["application/javascript", "application/x-www-form-urlencoded", "application/graphql"].includes(mediaType);
  if (textual) {
    const responseText = new TextDecoder().decode(responseBytes);
    let data = responseText;
    if (contentType.includes("json")) {
      try { data = JSON.parse(responseText); } catch { /* Keep the raw body. */ }
    }
    console.log(data);
  } else {
    console.log(`Received ${responseBytes.byteLength} binary bytes`);
  }
}
java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;

public class Main {
    public static void main(String[] args) throws Exception {
        final String BASE_URL = "https://api.justoneapi.com"; // 由 OpenAPI servers 提供
        final String url = BASE_URL + "/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE";

        HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(120)).build();
        HttpRequest.Builder builder = HttpRequest.newBuilder()
            .uri(URI.create(url))
            .timeout(Duration.ofSeconds(120))
            .method("GET", HttpRequest.BodyPublishers.noBody());

        HttpRequest request = builder.build();

        HttpResponse<byte[]> response = client.send(request, HttpResponse.BodyHandlers.ofByteArray());
        System.out.println(response.statusCode());
        String contentType = response.headers().firstValue("content-type").orElse("").toLowerCase();
        String mediaType = contentType.split(";", 2)[0].trim();
        if (contentType.startsWith("text/") || contentType.contains("json") || contentType.contains("xml") || mediaType.equals("application/javascript") || mediaType.equals("application/x-www-form-urlencoded") || mediaType.equals("application/graphql")) {
            System.out.println(new String(response.body(), StandardCharsets.UTF_8));
        } else {
            Files.write(Path.of("response.bin"), response.body());
            System.out.println("Saved " + response.body().length + " bytes to response.bin");
        }
    }
}
go
package main

import (
	"fmt"
	"io"
	"os"
	"strings"
	"net/http"
	"time"
)

const BASE_URL = "https://api.justoneapi.com" // 由 OpenAPI servers 提供

func main() {
	client := &http.Client{Timeout: 120 * time.Second}
	url := BASE_URL + "/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE"
	req, _ := http.NewRequest("GET", url, nil)
	resp, _ := client.Do(req)
	defer resp.Body.Close()
	fmt.Println(resp.StatusCode)
	bodyBytes, _ := io.ReadAll(resp.Body)
	contentType := strings.ToLower(resp.Header.Get("Content-Type"))
	mediaType := strings.TrimSpace(strings.SplitN(contentType, ";", 2)[0])
	if strings.HasPrefix(contentType, "text/") || strings.Contains(contentType, "json") || strings.Contains(contentType, "xml") || mediaType == "application/javascript" || mediaType == "application/x-www-form-urlencoded" || mediaType == "application/graphql" {
		fmt.Println(string(bodyBytes))
	} else {
		os.WriteFile("response.bin", bodyBytes, 0600)
		fmt.Printf("Saved %d bytes to response.bin\n", len(bodyBytes))
	}
}
php
<?php
$BASE_URL = 'https://api.justoneapi.com'; // 由 OpenAPI servers 提供
$url = $BASE_URL . '/api/bilibili/search-video/v2?token=YOUR_API_KEY&keyword=VALUE';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
$contentType = strtolower((string) curl_getinfo($ch, CURLINFO_CONTENT_TYPE));
curl_close($ch);
echo $status . PHP_EOL;
$mediaType = trim(explode(';', $contentType, 2)[0]);
if (str_starts_with($contentType, 'text/') || str_contains($contentType, 'json') || str_contains($contentType, 'xml') || in_array($mediaType, ['application/javascript', 'application/x-www-form-urlencoded', 'application/graphql'], true)) {
    echo $response;
} else {
    file_put_contents('response.bin', $response);
    echo 'Saved ' . strlen($response) . ' bytes to response.bin' . PHP_EOL;
}

返回字段 ​

业务成功时(code = 0)的主要返回字段。

搜索结果与分页8 个字段

data.data

当前页的搜索卡片和分页字段。

字段类型说明
pageinteger哔哩哔哩返回的当前页码。
pagesizeinteger哔哩哔哩返回的每页大小。当前页实际卡片数以 result 的长度为准。
numResultsinteger哔哩哔哩为本次搜索返回的结果数。
numPagesinteger哔哩哔哩返回的页数。请求页码超过这个值时,响应仍可能包含卡片。
nextinteger正值表示可用于续查的下一页页码。当前页仍有结果时,此字段也可能为 0。
suggest_keywordstring哔哩哔哩建议的替代搜索关键词,存在时可用。
resultarray当前页的搜索卡片,可能包含普通视频、课程或推广结果。卡片标题可能不包含搜索词原文。
result[]object一张搜索卡片。区分普通视频和其他结果时,请读取卡片的 type。
卡片内容15 个字段

data.data.result[]

字段类型说明
typestring搜索卡片的类型标签。普通视频、课程和推广卡片可能使用不同标签和字段。
idinteger搜索卡片返回的数字标识。
aidinteger卡片返回的哔哩哔哩数字内容 ID。
bvidstring存在时返回的哔哩哔哩 BV 标识。课程等卡片可能返回空字符串。
titlestring哔哩哔哩返回的结果标题,可能含标题高亮标记。
descriptionstring哔哩哔哩返回的结果简介。
descstring卡片返回的补充展示描述。
subtitlestring卡片返回的展示副标题,存在时可用。
arcurlstring卡片返回的内容页面链接。
urlstring卡片返回的打开地址。
picstring结果返回的主要图片地址,存在时可用。
coverstring卡片返回的封面图片地址,存在时可用。
pubdateinteger正值为发布时间,Unix 时间戳,单位为秒。部分卡片返回 0。
senddateinteger正值为投稿时间,Unix 时间戳,单位为秒。部分卡片返回 0。
durationstring用于展示的时长文本,例如以冒号分隔的分和秒。部分卡片可能为空。
作者与分区7 个字段

data.data.result[]

字段类型说明
tagstring以展示文本返回的结果关联标签。
typeidstring以文本表示的分区标识。
typenamestring结果返回的分区名称。
cate_namestring卡片返回的分类标签,存在时可用。
authorstring结果显示的投稿者或创作者名称。
midinteger结果关联的哔哩哔哩创作者数字 ID。
upicstring投稿者头像图片的地址。
互动数据6 个字段

data.data.result[]

字段类型说明
playinteger | null结果返回的播放次数,存在时可用。
favoritesinteger结果返回的收藏数。
reviewinteger结果返回的评论数。
video_reviewinteger视频结果返回的弹幕数。
danmakuinteger搜索卡片附带的另一项弹幕计数字段。
likeinteger结果返回的点赞数。
卡片展示与状态12 个字段

data.data.result[]

字段类型说明
cornerstring用于卡片展示的角标文字。
rec_reasonstring卡片返回的推荐理由,存在时可用。
hit_columnsarray | null搜索结果中标记为命中查询的字段列表,存在时可用。
hit_columns[]string一个标记为命中搜索的字段名称。
new_rec_tagsarray | null卡片返回的推荐标签字段。
view_typestring搜索卡片返回的展示类型标签。
badgepayboolean卡片是否标记为显示付费角标。
is_payinteger卡片返回的付费相关数字标记。
is_charge_videointeger视频是否标记为付费内容的数字标记。
is_union_videointeger视频是否标记为联合投稿的数字标记。
episode_count_textstring用于展示分集数或课时数的文字,存在时可用。
release_statusinteger卡片返回的发布状态数字代码。
平台响应状态3 个字段

data

哔哩哔哩搜索响应,包括平台状态及一页搜索结果。

字段类型说明
codeinteger哔哩哔哩为本次搜索返回的状态数字代码。
messagestring哔哩哔哩返回的搜索状态消息。
ttlinteger哔哩哔哩返回的 TTL 值。

响应示例 ​

正在加载响应示例…