
Public
Like
5
github-user-email
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Viewing readonly version of main branch: v221View latest version
TypeScript function to get a GitHub user's email from their public event commit history via the GitHub API.
This function pulls the user's recent public events.
import { emailsFromGitHubEvents } from "https://esm.town/v/stevekrouse/github-user-email/events.ts";
const emails = await emailsFromGitHubEvents("stevekrouse");
console.log(emails); // [ "steveykrouse@gmail.com" ]
The limitation is that this endpoint only gets events from the last 30 days, so if the user hasn't committed in the last month, you won't get any results from this method. (Coming soon: an additional method that gets around this limitation.)
The GitHub API
rate limits
unauthenticated requests to 60 per hour per IP address. As a quick workaround,
Val Town provides an IP-randomizer fetch
proxy that makes it easy to get
around these limits. These functions use that proxy by default. However, if
you're using these functions at scale, please use a GITHUB_TOKEN to be a good
GitHub citizen.
- Go to https://github.com/settings/personal-access-tokens/new
- Give it a name like
Get user emails
- Set the expiration appropriately (I recommend
No expiration
) - Click Generate token
- Copy the token into your val's env variables (in the left sidebar) as
GITHUB_TOKEN