I would like to access the content of a file I uploaded to GitHub via Node.js.
The GitHub repository is private, so I have generated an access token at https://github.com/settings/tokens
Unfortunately, I keep getting a 404 – Not found error. What am I doing wrong?
const request = require('request');
const URL = 'https://raw.githubusercontent.com/myuser/myrepo/master/myfile.js';
const TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var options = {
url: URL,
headers: {
'Authorization': TOKEN
}
};
function callback(error, response, body) {
console.log(response.statusCode);
console.error(error);
console.log(body);
}
request(options, callback);
Thanks to the comment of @bhavesh27 I figured, I was missing a "token " in my header.
const request = require('request');
const URL = 'https://raw.githubusercontent.com/myuser/myrepo/master/myfile.js';
const TOKEN = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
var options = {
url: URL,
headers: {
'Authorization': 'token ' + TOKEN
}
};
function callback(error, response, body) {
console.log(response.statusCode);
console.error(error);
console.log(body);
}
request(options, callback);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.