首页 > 解决方案 > 当我尝试登录时,GitHub API 返回消息需要身份验证

问题描述

const fetchUser =  async () =>{
    let username : any = (document.getElementById('username') as HTMLInputElement).value;
    let password : any = (document.getElementById('password') as HTMLInputElement).value; 
    const profile = await fetch("https://api.github.com/user", {
        headers:{
            'Authorization': 'Basic ' + window.btoa(username + ":" + password)
        }
    })
   const profileResponse = await profile.json()
    console.log(profileResponse)
}
const handleSubmit =(e:any) =>{
    e.preventDefault()
    fetchUser()
}

我尝试使用 GitHub API 使用 GitHub 凭据登录,但它返回所需的身份验证

标签: reactjstypescriptreduxgithub-api

解决方案


Github.com 已停止使用username和对 API 进行密码验证password

参考


推荐阅读