微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

gitee open API和GitHub restful API使用

说明

giteegithub都提供了丰富的restful API,用于开发人员操作仓库.

token获取

giteegithub私有仓库或者部分接口都需要用户权限认证,本文均使用token方式验证.

  • gitee token 获取
    选择用户 - 【设置】 - 【私人令牌】 - 生成新令牌】. 使用私人令牌,可以通过Gitee Open API访问你授权的数据.

  • github token 获取
    选择用户 - 【Settings】 - 【Developer settings】 - 【Personal access tokens】 - 【Generate new token】. Tokens you have generated that can be used to access the GitHub API.

gitee 接口测试

接口在线测试地址

curl -X POST --header 'Content-Type: application/json;charset=UTF-8' 'https://gitee.com/api/v5/repos/happywzy/issues' -d '{"access_token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","repo":"test","title":"测试ISSUE","body":"测试内容","labels":"bug"}'

github 接口测试

接口格式:https://api.github.com/repos/{用户名}/{仓库}/xxx

  • 获取公开仓库的issue列表
# 添加Accept头,指定返回内容类型
curl \
  -H "Accept: application/vnd.github.v3+json" \
  https://api.github.com/repos/octocat/hello-world/issues
  • 获取私有仓库的issue列表

github API传入token的几种方式,官方文档.

# header添加Authorization字段,注意字段的值是[token xxxxxx]格式
curl -v -H "Authorization: token xxxxxxxxxxxxxx" https://api.github.com/repos/xxx/admin/issues
# 请求URL后面增加access_token
https://api.github.com/repos/alfalfaw/vue-shop-admin?access_token=xxxxxxx

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐