1

console error :

al

code to reproduce error:

var request = require('request');
var url = 'http://api.stackexchange.com/2.2/https://stackoverflow.com/questions';
request({
headers: {
    'Accept': 'application/json; charset=utf-8',
    'User-Agent': 'RandomHeader'
         },
     uri: url,
     key: 'cawQTENGI5TpoSgBKy7SXw',
     method: 'GET',
     gzip: true
         },
  function(err, res, body) {
     console.log("response.statusCode" + res.statusCode);
     console.log('server encoded the data as: ' + (res.headers['content-encoding'] || 'identity'))
     console.log('the decoded data is: ' + body)
   });
export default {
  name: 'StackApi',
}

My intention is to get all questions, but the documentation of Stack Overflow is hard to understand for me, is it because I am accessing locally the data? I don't understand the Cross-Origin read blocking.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62

1 Answers1

0

You're using a wrong url

 var url = 'http://api.stackexchange.com/2.2/https://stackoverflow.com/questions';

it should be :

var url 'http://api.stackexchange.com//2.2/questions?order=desc&sort=activity&site=stackoverflow'

just provide the site name in your query

Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
  • tnx, it seems like I got a step farther in the request, although I am still getting an error on the request : Access to fetch at 'https://api.stackexchange.com//2.2/questions?order=desc&sort=activity&site=stackoverflow' (redirected from 'http://api.stackexchange.com//2.2/questions?order=desc&sort=activity&site=stackoverflow') from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled. –  Sep 17 '20 at 19:05
  • 1
    i used this api in my portfolio with axios and it worked fine without cors blocking – Boussadjra Brahim Sep 17 '20 at 19:08