Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于 BUVID3 获取方式 #790

Open
Colerar opened this issue Aug 20, 2023 · 2 comments
Open

关于 BUVID3 获取方式 #790

Colerar opened this issue Aug 20, 2023 · 2 comments
Labels
新增/Add 添加或修改新的内容 主站杂项/Misc 接口:主站其他类型

Comments

@Colerar
Copy link
Contributor

Colerar commented Aug 20, 2023

其实只用带正常浏览器 UA 访问一下 https://www.bilibili.com/ 即会下发 Set-Cookie 头,可通过对应框架的 cookie jar 功能获取:

❯ curl 'https://www.bilibili.com/' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/116.0' --compressed  --cookie-jar output.txt > output.html

❯ cat output.txt
# Netscape HTTP Cookie File
# https://curl.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

.bilibili.com	TRUE	/	FALSE	1724056902	b_ut	7
.bilibili.com	TRUE	/	FALSE	1724056902	i-wanna-go-back	-1
.bilibili.com	TRUE	/	FALSE	1724056902	b_nut	1692520902
.bilibili.com	TRUE	/	FALSE	1724056902	buvid3	97DA8E0D-C4ED-307A-9D01-1D5F335E1A8D02332infoc
.bilibili.com	TRUE	/	FALSE	0	innersign	0
@xiaoyv404 xiaoyv404 added 新增/Add 添加或修改新的内容 主站杂项/Misc 接口:主站其他类型 labels Aug 20, 2023
@z0z0r4
Copy link
Collaborator

z0z0r4 commented Aug 29, 2023

web 端丢失后会调用 spi 接口,返回 3/4 的 buvid,姿势比较优雅,这样拿 cookies 没必要
#795

@SessionHu
Copy link
Contributor

#338 提供了通过 API 仅获取 buvid3 的方法, 但这 PR 好像没人管...

## buvid
```shell
curl -H 'Host: api.bilibili.com' -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Google Chrome";v="99"' -H 'accept: application/json, text/plain, */*' -H 'sec-ch-ua-mobile: ?0' -H 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36' -H 'sec-ch-ua-platform: "macOS"' -H 'origin: https://www.biligame.com' -H 'sec-fetch-site: cross-site' -H 'sec-fetch-mode: cors' -H 'sec-fetch-dest: empty' -H 'referer: https://www.biligame.com/' -H 'accept-language: zh-CN,zh;q=0.9' --compressed 'https://api.bilibili.com/x/web-frontend/getbuvid'
```
```json
{"code":0,"data":{"buvid":"A2E7E681-1DE4-623F-8B08-B56D73F6C6C169792infoc"}}
```

于是在 #1088 添加了一段

## 仅获取 buvid3
> https://api.bilibili.com/x/web-frontend/getbuvid
*请求方式: GET*
<!--{
"gh": [338]
}-->
**JSON回复:**
根对象:
| 字段 | 类型 | 内容 | 备注 |
| ------- | ---- | -------- | -------- |
| code | num | 返回值 | 0:成功 |
| data | obj | 数据本体 | |
`data`对象:
| 字段 | 类型 | 内容 | 备注 |
| ---- | ---- | ------ | ---- |
| buvid | str | buvid3 | 需手动存放至 cookie 中 |
**示例:**
注: 不要复制
```shell
curl -G 'https://api.bilibili.com/x/web-frontend/getbuvid'
```
<details>
<summary>查看响应示例:</summary>
```json
{
"code": 0,
"data": {
"buvid": "54E5EFC1-3C8F-F690-2261-439E4F6A20A979439infoc"
}
}
```
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
新增/Add 添加或修改新的内容 主站杂项/Misc 接口:主站其他类型
Projects
None yet
Development

No branches or pull requests

4 participants