pksunkara / octonode

github api v3 in nodejs
MIT License
1.19k stars 237 forks source link

Ghsearch is acting very inconsistently: returning undefined sometimes and other times works without any change in code #326

Closed arjn137 closed 5 years ago

arjn137 commented 6 years ago
var github = require('octonode'),
    client = github.client(),
    ghsearch = client.search(),
    fs = require('fs');

for (var a = 1; a <= 10; a++) {
    ghsearch.repos({ q: 'd3js', per_page: 100, page: a }, function (err, data) {
        var stream = fs.createWriteStream("URLs.txt", { flags: 'a' });
        if (!err) {
            stream.once('open', function (fd) {
                for (var i = 0; i < data.items.length; i++) {
                    stream.write(data.items[i].html_url + "\n");
                }
                stream.end();
            });
        }
    });
}

I'm trying to get the URLs of every repository that has "d3js" in it, but the ghsearch.repos method is working extremely inconsistently. Right now the code just looks at the first 10 pages, but even when I don't change the code I can get an error saying the data is undefined or I can have a completely good working code that outputs to the file perfectly.

f3d0r commented 5 years ago

This could be caused by the request limit set for the GitHub API.

pksunkara commented 5 years ago

I am closing this because what @f3d0r said is most probably the correct answer.