"Error 415" when requesting Spotify for tokens

I am trying to recreate an oauth authentication connection in MeteorJS. I got to the request for access and update tokens, but now I get the 415 error all the time. Here is the corresponding code:

var results = HTTP.post( 'https://accounts.spotify.com/api/token', { data: { code: code, redirect_uri: redirectURI, grant_type: 'authorization_code', client_id: clientID, client_secret: clientSecret }, headers: { 'Content-Type':'application/json' } } ); 

I can't seem to find any other good documentation about the problem and the code in this demo:

https://github.com/spotify/web-api-auth-examples/tree/master/authorization_code

works great.

+7
spotify meteor
source share
3 answers

I had a similar problem (but in Java). A similar solution was

  headers: { 'Content-Type':'application/x-www-form-urlencoded' } 
+7
source share

When submitting a JSON object, you need to use params instead of data . Related question: Unsupported grant type error when access_token requested on Spotify API with Meteor HTTP

+2
source share

If you do this clientide, this does not work because you are not allowed to send to another domain on the client side due to the same origin policy .

If this is the server side, I would recommend using the previously existing apit npm spotify module instead of writing your own queries. There are many apify api options on npmjs.org .

Use arunoda npm package to integrate npm packages into your meteor application

-2
source share

All Articles