trakt / api-help

Trakt API docs at https://trakt.docs.apiary.io
186 stars 7 forks source link

Problem with CORS when using the API #426

Closed Ricrdsson1 closed 9 months ago

Ricrdsson1 commented 11 months ago

Hello, I have a problem with CORS verification when using your API on my Web site. I added my WEB in your interface to enable CORS but it probably doesn't work.

var request = new XMLHttpRequest();

request.open('POST', 'https://api.trakt.tv/oauth/device/code');

request.setRequestHeader('Content-Type', 'application/json');

request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

var body = {
  'client_id': 'xxx'
};

request.send(JSON.stringify(body));
rectifyer commented 9 months ago

Please try some code like this:

fetch('https://api.trakt.tv/oauth/device/code', {
  'headers': { 'content-type': 'application/json' },
  'referrer': 'https://yourdomain.com',
  'body': '{"client_id":"X"}',
  'method': 'POST'
});