【问题标题】:How to Star a Topic on GitHub with API?如何使用 API 在 GitHub 上为主题加注星标?
【发布时间】:2021-12-16 03:40:12
【问题描述】:

可以在网站上为主题加注星标。但是如何通过 GitHub API v3 或 v4 做同样的操作呢?我通读了参考资料,但没有任何线索。

【问题讨论】:

    标签: github github-api github-api-v3 github-api-v4


    【解决方案1】:

    对于 v3 REST API,它记录在 Star a repository for the authenticated user

    curl 例子是:

    curl \
      -X PUT \
      -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/user/starred/octocat/hello-world
    

    但这并没有显示如何插入你的令牌,所以你实际上需要更多类似的东西:

    curl \
      -X PUT \
      -H "Authorization: token $GITHUB_API_TOKEN" \
      -H "Accept: application/vnd.github.v3+json" \
      https://api.github.com/user/starred/octocat/hello-world
    

    GITHUB_API_TOKEN 之前的设置如下:

    GITHUB_API_TOKEN="ghp_16C7e42F292c6912E7710c838347Ae178B4a"
    

    对于这个较早的问题how to star a repo with github api,请确保所使用的令牌具有正确的加星权限,这意味着启用了 repo 范围(或至少 repo_public)。

    我也很想知道如何使用 v4 GraphQl API 做到这一点。

    【讨论】:

      猜你喜欢
      • 2018-12-07
      • 1970-01-01
      • 2014-08-27
      • 2012-12-13
      • 1970-01-01
      • 2013-05-22
      • 2020-10-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多