暂无
OAuth 2 / API 认证
在使用 API 之前,你需要 注册应用 并获得可以 OAuth App 信息。并使用标准的 OAuth 2 实现登录,获得 access_token
信息。
OAuth 路径
- https://diycode.cc/oauth/authorize
- https://diycode.cc/oauth/token
- https://diycode.cc/oauth/revoke
Response 说明
所有 Response 采用 JSON 格式返回,请求状态通过 HTTP Status 返回
HTTP Status
- 200, 201 - 请求成功,或执行成功
- 400 - 参数不符合 API 的要求、或者数据格式验证没有通过,请配合 Response Body 里面的 error 信息确定问题。
- 401 - 用户认证失败,或缺少认证信息,比如 access_token 过期,或没传,可以尝试用 refresh_token 方式获得新的 access_token。
- 403 - 当前用户对资源没有操作权限
- 404 - 资源不存在。
- 500 - 服务器异常
错误的情况 Response Body 一定会是这样的格式: { "error" : "Error message" }
资源权限描述
在部分 API 的 response 内容里面你会看到 abilities
节点,这是特别标识当前 access_token 对应的用户对此资源的权限
请参考源代码,确定那些路径是需要用户认证的,需要用户认证的路径,你需要带上 access_token=?
参数。
{
"topic": {
"id": 256170,
....,
"abilities": { "update": true, "destroy": true }
}
}
update
- 是否有权限修改destroy
- 是否有权限删除
API 路由
URL 基本路径:https://diycode.cc/api/v3
- ANY /*path.json
- POST /devices.json
- DELETE /devices.json
- OPTIONS /devices.json
- GET /hello.json
- OPTIONS /hello.json
- POST /likes.json
- DELETE /likes.json
- OPTIONS /likes.json
- GET /news.json
- POST /news.json
- OPTIONS /news.json
- GET /news/:id/replies.json
- OPTIONS /news/:id/replies.json
- GET /news/nodes.json
- OPTIONS /news/nodes.json
- GET /news_replies/:id.json
- POST /news_replies/:id.json
- DELETE /news_replies/:id.json
- OPTIONS /news_replies/:id.json
- GET /nodes.json
- OPTIONS /nodes.json
- GET /nodes/:id.json
- OPTIONS /nodes/:id.json
- GET /notifications.json
- OPTIONS /notifications.json
- DELETE /notifications/:id.json
- OPTIONS /notifications/:id.json
- DELETE /notifications/all.json
- OPTIONS /notifications/all.json
- POST /notifications/read.json
- OPTIONS /notifications/read.json
- GET /notifications/unread_count.json
- OPTIONS /notifications/unread_count.json
- POST /photos.json
- OPTIONS /photos.json
- GET /project_replies/:id.json
- POST /project_replies/:id.json
- DELETE /project_replies/:id.json
- OPTIONS /project_replies/:id.json
- GET /projects.json
- OPTIONS /projects.json
- GET /projects/:id/replies.json
- OPTIONS /projects/:id/replies.json
- GET /replies/:id.json
- POST /replies/:id.json
- DELETE /replies/:id.json
- OPTIONS /replies/:id.json
- GET /sites.json
- OPTIONS /sites.json
- GET /topics.json
- POST /topics.json
- OPTIONS /topics.json
- POST /topics/:id.json
- GET /topics/:id.json
- DELETE /topics/:id.json
- OPTIONS /topics/:id.json
- POST /topics/:id/ban.json
- OPTIONS /topics/:id/ban.json
- POST /topics/:id/favorite.json
- OPTIONS /topics/:id/favorite.json
- POST /topics/:id/follow.json
- OPTIONS /topics/:id/follow.json
- GET /topics/:id/replies.json
- POST /topics/:id/replies.json
- OPTIONS /topics/:id/replies.json
- POST /topics/:id/unfavorite.json
- OPTIONS /topics/:id/unfavorite.json
- POST /topics/:id/unfollow.json
- OPTIONS /topics/:id/unfollow.json
- GET /users.json
- OPTIONS /users.json
- GET /users/:login.json
- OPTIONS /users/:login.json
- POST /users/:login/block.json
- OPTIONS /users/:login/block.json
- GET /users/:login/blocked.json
- OPTIONS /users/:login/blocked.json
- GET /users/:login/favorites.json
- OPTIONS /users/:login/favorites.json
- POST /users/:login/follow.json
- OPTIONS /users/:login/follow.json
- GET /users/:login/followers.json
- OPTIONS /users/:login/followers.json
- GET /users/:login/following.json
- OPTIONS /users/:login/following.json
- GET /users/:login/replies.json
- OPTIONS /users/:login/replies.json
- GET /users/:login/topics.json
- OPTIONS /users/:login/topics.json
- POST /users/:login/unblock.json
- OPTIONS /users/:login/unblock.json
- POST /users/:login/unfollow.json
- OPTIONS /users/:login/unfollow.json
- GET /users/me.json
- OPTIONS /users/me.json
/*path.json
/devices.json
记录用户 Device 信息,用于 Push 通知。
请在每次用户打开 App 的时候调用此 API 以便更新 Token 的 last_actived_at 让服务端知道这个设备还活着。
Push 将会忽略那些超过两周的未更新的设备。
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
platform | String | true | ["ios", "android"] | ||
token | String | true |
/devices.json
删除 Device 信息,请注意在用户登出或删除应用的时候调用,以便能确保清理掉
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
platform | String | true | ["ios", "android"] | ||
token | String | true |
/devices.json
暂无
/hello.json
简单的 API 测试接口,需要验证,便于快速测试 OAuth 以及其他 API 的基本格式是否正确
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
limit | Integer | false | 0..100 |
/hello.json
暂无
/likes.json
暂无
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
obj_type | String | true | ["topic", "reply", "news"] | ||
obj_id | Integer | true |
/likes.json
取消之前的赞
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
obj_type | String | true | ["topic", "reply", "news"] | ||
obj_id | Integer | true |
/likes.json
暂无
/news.json
获取news 列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
node_id | Integer | false | 如果你需要只看某个节点的,请传此参数, 如果不传 则返回全部 |
||
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/news.json
创建News
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
title | String | true | News 标题 |
||
address | String | true | News 链接 |
||
node_id | Integer | true | News 节点编号 |
/news.json
暂无
/news/:id/replies.json
获取News 评论列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/news/:id/replies.json
暂无
/news/nodes.json
获取news分类列表
/news/nodes.json
暂无
/news_replies/:id.json
获取News评论的详细内容
/news_replies/:id.json
更新News 评论
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
body | String | true |
/news_replies/:id.json
删除News 评论
/news_replies/:id.json
暂无
/nodes.json
暂无
/nodes.json
暂无
/nodes/:id.json
暂无
/nodes/:id.json
暂无
/notifications.json
暂无
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/notifications.json
暂无
/notifications/:id.json
删除当前用户的某个通知
/notifications/:id.json
暂无
/notifications/all.json
删除当前用户的所有通知
/notifications/all.json
暂无
/notifications/read.json
将当前用户的一些通知设成已读状态
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
ids | Array | true |
/notifications/read.json
暂无
/notifications/unread_count.json
获得未读通知数量
/notifications/unread_count.json
暂无
/photos.json
上传图片,请使用 Multipart 的方式提交图片文件
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
file | true | Image file. |
/photos.json
暂无
/project_replies/:id.json
获取项目评论的详细内容
/project_replies/:id.json
更新Project 评论
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
body | String | true |
/project_replies/:id.json
删除Project 评论
/project_replies/:id.json
暂无
/projects.json
获取news 列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
node_id | Integer | false | 如果你需要只看某个节点的,请传此参数, 如果不传 则返回全部 |
||
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/projects.json
暂无
/projects/:id/replies.json
获取项目 评论列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/projects/:id/replies.json
暂无
/replies/:id.json
获取回帖的详细内容(一般用于编辑回帖的时候)
/replies/:id.json
更新回帖
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
body | String | true |
/replies/:id.json
删除回帖
/replies/:id.json
暂无
/sites.json
获取sites 列表
/sites.json
暂无
/topics.json
暂无
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
type | String | false | last_actived | ["last_actived", "recent", "no_reply", "popular", "excellent"] | |
node_id | Integer | false | 如果你需要只看某个节点的,请传此参数 |
||
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/topics.json
创建话题
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
title | String | true | 话题标题 |
||
body | String | true | 话题内容, Markdown 格式 |
||
node_id | Integer | true | 节点编号 |
/topics.json
暂无
/topics/:id.json
更新话题
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
title | String | true | 话题标题 |
||
body | String | true | 话题内容, Markdown 格式 |
||
node_id | Integer | true | 节点编号 |
/topics/:id.json
暂无
/topics/:id.json
暂无
/topics/:id.json
暂无
/topics/:id/ban.json
屏蔽话题,移到 NoPoint 节点 (Admin only)
/topics/:id/ban.json
暂无
/topics/:id/favorite.json
收藏话题
/topics/:id/favorite.json
暂无
/topics/:id/follow.json
关注话题
/topics/:id/follow.json
暂无
/topics/:id/replies.json
获取话题评论
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/topics/:id/replies.json
创建回帖
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
body | String | true | 回帖内容, Markdown 格式 |
/topics/:id/replies.json
暂无
/topics/:id/unfavorite.json
取消收藏话题
/topics/:id/unfavorite.json
暂无
/topics/:id/unfollow.json
取消关注话题
/topics/:id/unfollow.json
暂无
/users.json
暂无
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
limit | Integer | false | 20 | 1..150 |
/users.json
暂无
/users/:login.json
获取用户详细资料
/users/:login.json
暂无
/users/:login/block.json
屏蔽用户
/users/:login/block.json
暂无
/users/:login/blocked.json
用户屏蔽的用户
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/blocked.json
暂无
/users/:login/favorites.json
用户收藏的话题列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/favorites.json
暂无
/users/:login/follow.json
关注用户
/users/:login/follow.json
暂无
/users/:login/followers.json
用户的关注者列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/followers.json
暂无
/users/:login/following.json
用户正在关注的人
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/following.json
暂无
/users/:login/replies.json
获取用户创建的回帖列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
order | String | false | recent | ["recent"] | |
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/replies.json
暂无
/users/:login/topics.json
获取用户创建的话题列表
Params
参数名 | 类型 | 必填 | 默认值 | 值范围 | 说明 |
---|---|---|---|---|---|
order | String | false | recent | ["recent", "likes", "replies"] | |
offset | Integer | false | 0 | ||
limit | Integer | false | 20 | 1..150 |
/users/:login/topics.json
暂无
/users/:login/unblock.json
取消屏蔽用户
/users/:login/unblock.json
暂无
/users/:login/unfollow.json
取消关注用户
/users/:login/unfollow.json
暂无
/users/me.json
获取当然登陆者的资料
/users/me.json
暂无
Example
我们用 Ruby 演示一下访问 /api/v3/hello.json 这个路径,其中包含 OAuth 2 的流程。
这里用到 RubyGem oauth2
=> require "oauth2"
=> client = OAuth2::Client.new('client id', 'secret', site: 'https://diycode.cc')
=> access_token = client.password.get_token('username', 'password')
=> Faraday.get("https://diycode.cc/api/v3/hello.json?access_token=#{access_token.token}").body
{ 'current_user' : 'username' }