最近在研究通过API获取gitlab仓库代码提交记录:官方API

发现API中是使用The ID or URL-encoded path of the project 来区分项目的。
为了方便与准确当然是使用ID最好了,对于自己是仓库管理员的项目,projectID是比较方面找到的,路径如下
Settings -> General project settings -> Expand -> Project ID
但是如果自己仅能访问,无法进入设置界面的仓库怎么获取Project ID呢?
方法有二:
- 方法一:直接get请求
查询指定项目:https://gitlab.com/api/v4/projects?search=projectname
查询完整列表:https://gitlab.com/api/v4/projects
但是这样的话,只会显示public的项目,如果想要查询私有仓库,需要携带参数private token
个人账号-Profile Settings-account 生成api private token
api/v3 版本
https://gitlab.example.com/api/v3/projects?simple=true&private-token= <your_access_token>
api/v4 版本
curl --header “PRIVATE-TOKEN: <your_access_token>” “https://gitlab.example.com/api/v4/projects?simple=true”
方法二(最快捷):
进入目标项目页面-显示网页源代码,直接搜索:project_id。

本文介绍两种获取GitLab项目ID的方法:一是通过API查询,携带私有令牌访问私有仓库;二是快速查找网页源代码中的project_id。

1287

被折叠的 条评论
为什么被折叠?



