【问题标题】:Github Apps identification of usersGithub Apps 用户识别
【发布时间】:2021-10-24 06:23:51
【问题描述】:

我开发了一个 github 应用程序,它监听合并事件并向组织提供分析。应用程序具有用户:读取权限。要将 git 用户映射到我的应用程序用户,我们需要一个电子邮件 ID。我尝试在 API 下方调用,但它总是将电子邮件设为 null(可能是这些用户没有公开他们的电子邮件。)。无论个人资料设置如何,我们如何访问电子邮件? .有没有其他方法可以将 git 用户映射到我们的应用用户(我们只有电子邮件和用户名)

Request req = new Request.Builder()
                .url("https://api.github.com/user/emails" + userName)
                .header("Authorization", "Bearer " + installationToken)
                .get()
                .build();
        Response resp = client.newCall(req).execute();
        String jsonResp2 = resp.body().string();
        Map userDetail = gson.fromJson(jsonResp2, Map.class);
        String email = userDetail.get("email").toString();

【问题讨论】:

    标签: github github-api-v3 github-app


    【解决方案1】:

    您的代码构造了一个错误的 URL:

    .url("https://api.github.com/user/emails" + userName)
    

    根据the docshttps://api.github.com/user/emails URL(末尾没有用户名,在您的代码中甚至没有用斜杠分隔)将为您提供当前经过身份验证的用户的电子邮件地址 仅限于其他用户。

    你需要的是这个:

    .url("https://api.github.com/users/" + userName)
    

    the documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 2023-03-25
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-18
      • 2022-01-14
      相关资源
      最近更新 更多