Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Request forbidden while accessing github api on node.js program

Tags:

I'm trying to run this code but getting this error:

Request forbidden by administrative rules, make sure your request has a User-Agent header

var https = require("https"); var username = 'jquery';  var options = { host: 'api.github.com', path: '/users/' + username + '/repos', method: 'GET' };  var request = https.request(options, function(response){ var body = ''; response.on("data", function(chunk){     body += chunk.toString('utf8'); });  response.on("end", function(){     console.log("Body: ", body);     }); });  request.end(); 
like image 879
Nicky Avatar asked Jan 27 '14 14:01

Nicky


1 Answers

Your options object does not have the headers option, describing the user-agent. Try this:

var options = {     host: 'api.github.com',     path: '/users/' + username + '/repos',     method: 'GET',     headers: {'user-agent': 'node.js'} }; 
like image 191
Rodrigo Medeiros Avatar answered Apr 05 '23 10:04

Rodrigo Medeiros