小编ada*_*iec的帖子

使用请求的请求函数时,Github API使用403进行响应

我正在尝试向github的API发出请求.这是我的要求:

var url = 'https://api.github.com/' + requestUrl + '/' + repo + '/';

request(url, function(err, res, body) {
    if (!err && res.statusCode == 200) {

        var link = "https://github.com/" + repo;
        opener(link);
        process.exit();

    } else {
        console.log(res.body);
        console.log(err);
        console.log('This ' + person + ' does not exist');
        process.exit();
    }

});
Run Code Online (Sandbox Code Playgroud)

这是我得到的答复:

Request forbidden by administrative rules. Please make sure your request has a User-Agent header (http://developer.github.com/v3/#user-agent-required). Check https://developer.github.com for other possible causes.
Run Code Online (Sandbox Code Playgroud)

我过去使用过完全相同的代码,但它已经有效了.请求不会抛出任何错误.现在我很困惑为什么我得到403(禁止)?有解决方案吗

request node.js github-api

6
推荐指数
2
解决办法
4411
查看次数

使用回调和函数作为go中的类型

我试图创建一种类似于Go中的Express(NodeJS)路由方法的函数:

app.get("route/here/", func(req, res){
    res.DoStuff()
});    
Run Code Online (Sandbox Code Playgroud)

在这个例子中,我希望"foo"(类型)与上述方法中的匿名函数相同.这是我使用Go失败的尝试之一:

type foo func(string, string)

func bar(route string, io foo) {
        log.Printf("I am inside of bar")
        // run io, maybe io() or io(param, param)?
}

func main() {
        bar("Hello", func(arg1, arg2) {
                return  arg + arg2
        })
}
Run Code Online (Sandbox Code Playgroud)

我怎么能解决我的困境?我不应该使用类型并使用其他东西吗?我有什么选择?

go

2
推荐指数
1
解决办法
1109
查看次数

标签 统计

github-api ×1

go ×1

node.js ×1

request ×1