【问题标题】:In Github API, how can one distinguish a user from an organisation?在 Github API 中,如何区分用户和组织?
【发布时间】:2018-01-16 06:52:49
【问题描述】:

获取以下 Github URL:https://github.com/google

如何确定google 是用户还是组织?

我需要知道这一点才能以正确的方式查询 Github 的 graphql API。

【问题讨论】:

    标签: github github-api github-graphql


    【解决方案1】:

    如果您有用户/组的登录名(用户名),您可以使用organization & user 分别搜索一个组织和一个用户,并检查这两个字段中哪个不是null

    {
      org: organization(login: "google") {
        name
        members {
          totalCount
        }
      }
      user: user(login: "google") {
        name
        login
      }
    }
    

    给出:

    {
      "data": {
        "org": {
          "name": "Google",
          "members": {
            "totalCount": 1677
          }
        },
        "user": null
      }
    }
    

    或为login 输入使用变量,try it in the explorer

    对于 Rest API v3,它要简单得多,因为它不区分用户和组织:https://developer.github.com/v3/users

    curl -s 'https://api.github.com/users/google' | jq -r '.type'
    

    组织

    curl -s 'https://api.github.com/users/torvalds' | jq -r '.type'
    

    用户

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2016-02-12
      • 1970-01-01
      • 2015-04-05
      • 1970-01-01
      相关资源
      最近更新 更多