API 2.0 Beta 是我们正在持续更新中的新接口,会提供一系列通过 Personal Access Token 访问 V2EX 功能的新方式。
如果你在使用过程中遇到任何疑问,欢迎来到 V2EX API 节点讨论。
Personal Access Token 可以在 Authorization header 中使用,例子如下:
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
所有 2.0 的 RESTful 的 API 接口都位于下面的这个前缀下:
https://study.congcong.us/api/v2/
| 接口 | HTTP 方法 | 结果 |
| notifications | GET | 获取最新的提醒 |
| notifications/:notification_id | DELETE | 删除指定的提醒 |
| member | GET | 获取自己的 Profile |
| token | GET | 查看当前使用的令牌 |
| nodes/:node_name | GET | 获取指定节点 |
| nodes/:node_name/topics | GET | 获取指定节点下的主题 |
| topics/:topic_id | GET | 获取指定主题 |
| topics/:topic_id/replies | GET | 获取指定主题下的回复 |
| topics/:topic_id/set-sticky | POST | 置顶主题 |
| topics/:topic_id/boost | POST | 放置主题到首页 |
推荐你可以在 VS Code 中安装和使用 REST Client 来测试这些 API。
默认情况下,每个 IP 每小时可以发起的 API 请求数被限制在 600 次。你可以在 API 返回结果的 HTTP 头部找到 Rate Limit 信息:
X-Rate-Limit-Limit: 120
X-Rate-Limit-Reset: 1409479200
X-Rate-Limit-Remaining: 116
对于能够被 CDN 缓存的 API 请求,只有第一次请求时,才会消耗 Rate Limit 配额。
下面是具体的接口访问信息。
GET notifications
可选参数:
p - 分页页码,默认为 1完整例子:
GET https://study.congcong.us/api/v2/notifications?p=2
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
DELETE notifications/:notification_id
完整例子:
DELETE https://study.congcong.us/api/v2/notifications/123456
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
GET member
完整例子:
GET https://study.congcong.us/api/v2/member
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
GET token
完整例子:
GET https://study.congcong.us/api/v2/token
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
POST tokens
你可以在系统中最多创建 10 个 Personal Access Token。
输入参数:
完整例子:
POST https://study.congcong.us/api/v2/tokens
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
{"scope": "everything", "expiration": 2592000}
GET nodes/:node_name
完整例子:
GET https://study.congcong.us/api/v2/nodes/python
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
GET nodes/:node_name/topics
可选参数:
p - 分页页码,默认为 1完整例子:
GET https://study.congcong.us/api/v2/nodes/python/topics?p=2
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
GET topics/:topic_id
完整例子:
GET https://study.congcong.us/api/v2/topics/1
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
GET topics/:topic_id/replies
可选参数:
p - 分页页码,默认为 1完整例子:
GET https://study.congcong.us/api/v2/topics/1/replies?p=2
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
POST topics/:topic_id/set-sticky
可选参数:
duration - 置顶时间长度,可用的值包括 15min(15 分钟),1hr(1 小时)和 8hr(8 小时)。如果没有提供,默认是 15min完整例子:
POST https://study.congcong.us/api/v2/topics/1/set-sticky?duration=1hr
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
curl 例子:
curl -X POST \
-H "Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146" \
"https://study.congcong.us/api/v2/topics/1/set-sticky?duration=1hr"
POST topics/:topic_id/boost
将自己的主题放置到首页。需要主题创建者本人操作,且需要是 PRO 用户或持有 50000 以上 Token。费用为 100 铜币。如果是创建在过去年度的主题,会根据主题年份增加费用。
完整例子:
POST https://study.congcong.us/api/v2/topics/1/boost
Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146
curl 例子:
curl -X POST \
-H "Authorization: Bearer bd1f2c67-cc7f-48e3-a48a-e5b88b427146" \
"https://study.congcong.us/api/v2/topics/1/boost"