提问者:小点点

用于获取不在Node.js中工作的github回购的Api


我已经在github的Oauth中注册了我的应用程序

//@router GET api/profile/github/:githubUsername 
//@desc   get github profile 
//@access public
router.get('/github/:githubUsername', (req,res)=>{
try {
    const options = {
        uri:`https://api.github.com/users/${req.params.githubUsername}
            /repos?per_page=5&sort=created:asc&client_id=${config.get('githubClientId')}
            &client_secret=${config.get('githubSecretKey')}`,
        method: 'GET',
        headers: { 'user-agent':'node.js' }
    };

    request(options, (err, response, body)=>{

        if(err) console.error(err)

        if(response.statusCode!==200) return res.status(404).json({msg : 'Github user not found'})

        res.status(200).json(JSON.parse(body));

    })

} catch (error) {
    console.log(error);
    res.status(500).send('Server Error');
}
})

此URL在浏览器中直接使用时正常工作。 它给出状态404。 我已经用clientId和secret key检查过了,它们工作正常。 我也不确定在github OAuth应用程序的回调URL中粘贴什么URL。

提前谢谢你。


共1个答案

匿名用户

url换行符是问题所在。 谢啦!