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.

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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 'api.stackexchange.com//2.2/…' (redirected from 'api.stackexchange.com//2.2/…) from origin '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.
i used this api in my portfolio with axios and it worked fine without cors blocking

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.