4

I have developed an github app which listens to merge event and provide analytics to the organization. App have user:read permission. To map git users with my app users we need an email id. I tried calling below API but it always gives email as null (may be these users don't have their email as public.) . How can we access the email irrespective of profile setting? . Is there any other way we I can map git user to our app users (we only have email and names of users)

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();
Rishi Saraf
  • 1,644
  • 2
  • 14
  • 27

1 Answers1

0

Your code constructs a wrong URL:

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

According to the docs, the https://api.github.com/user/emails URL (without the userName at the end, which in your code is not even separated by a slash) will give you the email addresses of the currently authenticated user only, not any other user.

What you need is this:

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

See the documentation.

Robert Mikes
  • 1,179
  • 8
  • 19