'Getting 401 Unauthorized error while requasting GitHub API
Good evening. My task is to create a website with react that will list through github users. I was following this instruction: https://docs.github.com/en/rest/users/users#get-a-user (for JS). My credentials:
async function searchUsers() {
try {
const octokit = new Octokit({
auth: 'ghp_MY_PERSONAL_TOKEN',
acceptstring: 'application/vnd.github.v3+json'
})
const response = await octokit.request(`GET /users/${name}`, {
username: 'maria98kgm'
});
setUsers(response.data);
setLoading(false);
searchRepos();
}
catch(e) {
setLoading(false);
setUsers('notFound');
console.error('no such a user');
}
}
Whenever i use it too long or push changes to github, it stops working and gives me 401 Unauthorized error:

I cannot solve it for two days already, please help.
Solution 1:[1]
Explanation of the error.
The 404 status code means your authentication data are not the good ones.
How to solve it.
- First, check your GitHub personal token is ok (i am guessing it is)
- Second, do the following : https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | alexzerah |
