1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
use serde_json::json;
use crate::{ BilibiliRequest, BpiClient, BpiError, BpiResponse };
impl BpiClient {
/// 点赞动态
///
/// # 文档
/// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic)
///
/// # 参数
///
/// | 名称 | 类型 | 说明 |
/// | ---- | ---- | ---- |
/// | `dyn_id_str` | &str | 动态 ID |
/// | `up` | u8 | 点赞状态:0 切换,1 点赞,2 取消 |
pub async fn dynamic_like(
&self,
dyn_id_str: &str,
up: u8
) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let csrf = self.csrf()?;
let json_body =
json!({
"dyn_id_str": dyn_id_str,
"up": up ,
"spmid":"333.1369.0.0",
"from_spmid":"333.999.0.0"
});
self
.post("https://api.bilibili.com/x/dynamic/feed/dyn/thumb")
.query(&[("csrf", csrf)])
.json(&json_body)
.send_bpi("点赞动态").await
}
/// 删除定时发布动态
///
/// # 文档
/// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic)
///
/// # 参数
///
/// | 名称 | 类型 | 说明 |
/// | ---- | ---- | ---- |
/// | `draft_id` | &str | 定时发布动态 ID |
pub async fn dynamic_remove_draft(
&self,
draft_id: &str
) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let csrf = self.csrf()?;
self
.post("https://api.vc.bilibili.com/dynamic_draft/v1/dynamic_draft/rm_draft")
.form(
&[
("draft_id", draft_id),
("csrf", csrf.as_str()),
]
)
.send_bpi("删除定时发布动态").await
}
/// 设置置顶动态
///
/// # 文档
/// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic)
///
/// # 参数
///
/// | 名称 | 类型 | 说明 |
/// | ---- | ---- | ---- |
/// | `dyn_str` | &str | 动态 ID |
pub async fn dynamic_set_top(
&self,
dyn_str: &str
) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let csrf = self.csrf()?;
let json_body = json!({
"dyn_str": dyn_str,
});
self
.post("https://api.bilibili.com/x/dynamic/feed/space/set_top")
.query(&[("csrf", csrf)])
.json(&json_body)
.send_bpi("设置置顶动态").await
}
/// 取消置顶动态
///
/// # 文档
/// [查看API文档](https://github.com/SocialSisterYi/bilibili-API-collect/tree/master/docs/dynamic)
///
/// # 参数
///
/// | 名称 | 类型 | 说明 |
/// | ---- | ---- | ---- |
/// | `dyn_str` | &str | 动态 ID |
pub async fn dynamic_remove_top(
&self,
dyn_str: &str
) -> Result<BpiResponse<serde_json::Value>, BpiError> {
let csrf = self.csrf()?;
let json_body = json!({
"dyn_str": dyn_str,
});
self
.post("https://api.bilibili.com/x/dynamic/feed/space/rm_top")
.query(&[("csrf", csrf)])
.json(&json_body)
.send_bpi("取消置顶动态").await
}
}
#[cfg(test)]
mod tests {
use super::*;
#[tokio::test]
async fn test_dynamic_like() {
let bpi = BpiClient::new();
let dynamic_id = "1099138163191840776";
// 测试新版点赞 API
let resp_new = bpi.dynamic_like(dynamic_id, 1).await;
assert!(resp_new.is_ok());
}
#[tokio::test]
#[ignore]
async fn test_dynamic_top() {
let bpi = BpiClient::new();
// 替换为你需要置顶或取消置顶的动态ID
let dynamic_id = "1099138163191840776";
// 测试置顶
let resp_set_top = bpi.dynamic_set_top(dynamic_id).await;
assert!(resp_set_top.is_ok());
// 测试取消置顶
let resp_rm_top = bpi.dynamic_remove_top(dynamic_id).await;
if resp_rm_top.is_err() {
tracing::info!("取消置顶失败: {}", resp_rm_top.err().unwrap());
}
}
}