Help us learn about your current experience with the documentation. Take the survey.

用户关注与取消关注 API

  • Tier: Free, Premium, Ultimate
  • Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated

使用此 API 执行用户账户的关注者操作。更多信息,请参阅关注用户

关注用户

关注指定的用户账户。

POST /users/:id/follow

支持的属性:

属性 类型 必需 描述
id integer 用户账户 ID

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/users/3/follow"

示例响应:

{
  "id": 1,
  "username": "john_smith",
  "name": "John Smith",
  "state": "active",
  "locked": false,
  "avatar_url": "http://localhost:3000/uploads/user/avatar/1/cd8.jpeg",
  "web_url": "http://localhost:3000/john_smith"
}

取消关注用户

取消关注指定的用户账户。

POST /users/:id/unfollow

支持的属性:

属性 类型 必需 描述
id integer 用户账户 ID

示例请求:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/users/3/unfollow"

列出关注某用户的所有账户

列出关注指定用户的所有用户账户。

GET /users/:id/followers

支持的属性:

属性 类型 必需 描述
id integer 用户账户 ID

示例请求:

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>"  "https://gitlab.example.com/users/3/followers"

示例响应:

[
  {
    "id": 2,
    "name": "Lennie Donnelly",
    "username": "evette.kilback",
    "state": "active",
    "locked": false,
    "avatar_url": "https://www.gravatar.com/avatar/7955171a55ac4997ed81e5976287890a?s=80&d=identicon",
    "web_url": "http://127.0.0.1:3000/evette.kilback"
  },
  {
    "id": 4,
    "name": "Serena Bradtke",
    "username": "cammy",
    "state": "active",
    "locked": false,
    "avatar_url": "https://www.gravatar.com/avatar/a2daad869a7b60d3090b7b9bef4baf57?s=80&d=identicon",
    "web_url": "http://127.0.0.1:3000/cammy"
  }
]

列出某用户关注的所有账户

列出指定用户正在关注的所有用户账户。

GET /users/:id/following

支持的属性:

属性 类型 必需 描述
id integer 用户账户 ID

示例请求:

curl --request GET --header "PRIVATE-TOKEN: <your_access_token>"  "https://gitlab.example.com/users/3/following"