403, ale tylko w terminalu edytora przy zapytaniu do API githuba

0

No dzień dobry,
Próbuję pobrać dane z api githuba w node js. Jak wrzucam załączony kod do codesandbox.io to normalnie mi wrzuca wynik do konsoli, ale jak odpalam w terminalu edytora node srcipt.js to dostaję od githuba 403, mimo że testowałem jeszcze jakieś open g**no api o kotach to zwracało mi dane w terminalu. Ktoś wyjaśni czym sie różni WebStorm od codesandbox.io w tym kontekście?

W insomnii (alternatywa postmana) też działa, no w sumie wystarczy sprawdzić link z geta w przeglądarce i widać, że nie trzeba żadnych autoryzacji.

const https = require("https");

https
  .get("https://api.github.com/users/gaearon", (res) => {
    const { statusCode } = res;
    const contentType = res.headers["content-type"];

    let error;
    // Any 2xx status code signals a successful response but
    // here we're only checking for 200.
    if (statusCode !== 200) {
      error = new Error("Request Failed.\n" + `Status Code: ${statusCode}`);
    } else if (!/^application\/json/.test(contentType)) {
      error = new Error(
        "Invalid content-type.\n" +
          `Expected application/json but received ${contentType}`
      );
    }
    if (error) {
      console.error(error.message);
      // Consume response data to free up memory
      res.resume();
      return;
    }
    res.setEncoding("utf8");
    let rawData = "";
    res.on("data", (chunk) => {
      rawData += chunk;
    });
    res.on("end", () => {
      try {
        const parsedData = JSON.parse(rawData);
        console.log(parsedData);
      } catch (e) {
        console.error(e.message);
      }
    });
  })
  .on("error", (err) => {
    console.log("Error: ", err.message);
  });

2

W wyniku połączenia przez HTTP/2 jest następujący tekst:

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.

Poniższy kod dodaje ten nagłówek.

const options = {
  hostname: "api.github.com",
  path: "/users/gaearon",
  headers: { "User-Agent": "Mozilla/5.0" }
};
https.get(options, (res) => {
// ...
}

1 użytkowników online, w tym zalogowanych: 0, gości: 1