Created
April 13, 2023 12:45
-
-
Save felladrin/7fe563974db0d2de6e881228897604aa to your computer and use it in GitHub Desktop.
DevTools script: Follow a list of GitHub users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @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