通过github api获取私有repo分支



我想通过github api在我的私人repo中获得所有分支名称。当我使用cli时,它是成功的,但当我在react应用程序中使用axios时,我得到错误代码404。我确信我的url和令牌在cli和react app中都是正确的。顺便说一下,我的react应用程序可以成功地获得公共的repo分支名称,但不包括私有的。

my Js code

const owner = 'Solo-steven';
const token = MYTOKEN;
const repo = 'Sideex-private-test'
async function getPrivateBranchName(){
await axios({
method: 'get',
url : `https://api.github.com/repos/${owner}/${repo}/branches`,
header:{
Authorization: `token ${token}`
}
}).then(response=>{
console.log(response, `Success get all branch name of repo(${repo}).`)
}).catch(response=>{
console.log(response, `error when get branch name of repo(${repo})`);
})
}

我的Cli

curl -H "Authorization: token MYTOKEN" https://api.github.com/repos/Solo-steven/Sideex-private-test/branches

根据https://www.npmjs.com/package/axios,它是头而不是头

最新更新