Nuxt.jsでSpotify APIを叩きたいです。
アクセストークンを取得するためにmounted
で以下のようなコードを書いてみたのですが、Access to XMLHttpRequest at 'https://accounts.spotify.com/api/token' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field grant_type is not allowed by Access-Control-Allow-Headers in preflight response.
というエラーが出てしまいました。
このエラーを解消するにはどうすればよいでしょうか?
mounted() { const options = { method: 'POST', headers: { Authorization: 'Basic MmM2Y2JlMjg3OWUwNGFkNzk3NTI0NDExZGYzZWJjNTU6YzA3YjkxYTk0OWQwNDFiZTk1ZjhlOWY3NjAzZjBiYTA=', grant_type: 'client_credentials' }, url: 'https://accounts.spotify.com/api/token' } this.$axios(options).then((res) => { console.log(res) }) }
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。