用户信息
冰橙课件
获取个人信息
Method and URL Structure
| Method |
Resource URL |
Authorization |
| GET |
/api/account/whoami/ |
YES |
cURL Example
curl -X GET -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' -H 'Content-Type: application/json' http://localhost/api/account/whoami/
Response Data
| Name |
Description |
| nickname |
昵称 |
| avatar_url |
头像地址 |
| slogan |
个性签名 |
| name |
姓名 |
| sex |
性别 |
| teacher_or_student |
用户身份:老师(teacher)或学生(student) |
Response
{ "pk": 3, "owner": "pk" "nickname":"xiaoming", "avatar_url":"http://www.example.com/xiaoming.jpg", "slogan":"xiaoming's slogan", "name": "小明", "sex": "M", "sex_display": "男", "teacher_or_student": "student",}
更新个人信息
使用 PUT 更新信息,未更新字段也传递给接口
使用 PATCH 更新信息,可更新一个或多个字段
Method and URL Structure
| Method |
Resource URL |
Descrtipion |
Authorization |
| PUT |
/api/account/whoami/ |
更新所有字段 |
YES |
| PATCH |
/api/account/whoami/ |
更新部分字段 |
YES |
Request Data
| Name |
Description |
Required |
Default |
| nickname |
昵称 |
YES |
|
| avatar_url |
头像地址 |
YES |
|
| slogan |
个性签名 |
YES |
|
| name |
姓名 |
YES |
|
| sex |
性别 |
YES |
|
sex choices
| Name |
Description |
| M |
男 |
| F |
女 |
| S |
保密 |
Request
{ "nickname":"新昵称", "avatar_url":"http://www.example.com/test001.jpg", "slogan":"xiaoming's slogan", "name": "小明", "sex": "M",}
cURL Example
curl -X PUT -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b'\-H 'Content-Type: application/json' --data '{....}' http://localhost/api/account/whoami/
Response
{ "nickname":"新昵称", "avatar_url":"http://www.example.com/test001.jpg", "slogan":"xiaoming's slogan", "address":u'南柯郡汶汶乡大槐树', "point": 100, "name": "小明", "sex": "M", "sex_display": "男",}
获取其他用户的公开信息
Method and URL Structure
| Method |
Resource URL |
Authorization |
| GET |
/api/account/pepole/${username}/ |
NO |
cURL Example
curl -X GET -H 'Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' -H 'Content-Type: application/json' http://localhost/api/account/pepole/1324567890/
Response
{ "pk": 3, "owner": "39" "nickname":"xiaoming", "avatar_url":"http://www.example.com/xiaoming.jpg", "slogan":"xiaoming's slogan", "name": "小明", "sex": "M", "sex_display": "男",}