Skip to content

Instantly share code, notes, and snippets.

@felladrin
Created April 13, 2023 12:45
Show Gist options
  • Save felladrin/7fe563974db0d2de6e881228897604aa to your computer and use it in GitHub Desktop.
Save felladrin/7fe563974db0d2de6e881228897604aa to your computer and use it in GitHub Desktop.
DevTools script: Follow a list of GitHub users
/** @see https://docs.github.com/en/rest/users/followers?apiVersion=2022-11-28#follow-a-user */
(async () => {
// Generate a fine-grained token with the following "Followers" scope (read/write) at https://github.com/settings/tokens
const token = "YOUR_GITHUB_TOKEN";
const usernames = ["XXX", "YYY", "ZZZ"];
const headers = {
Accept: "application/vnd.github+json",
Authorization: `Bearer ${token}`,
"X-GitHub-Api-Version": "2022-11-28",
};
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
for (const username of usernames) {
const response = await fetch(
`https://api.github.com/user/following/${username}`,
{
method: "PUT",
headers,
}
);
if (response.ok) {
console.log(`Followed ${username} successfully!`);
} else {
console.error(`Failed to follow ${username}.`);
}
await delay(1000);
}
console.log("All done!");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment