Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotify API Wrapper not working #4

Open
ironjaw72 opened this issue Aug 17, 2023 · 1 comment
Open

Spotify API Wrapper not working #4

ironjaw72 opened this issue Aug 17, 2023 · 1 comment

Comments

@ironjaw72
Copy link

I get a 403 error (unauthorized) when trying to use the wrapper (wrapWebApi) feature. I put the exact example code with my spDcCookie info and it doesn't work. The same cookie and code works fine when not using the wrapper.

const SpotifyWebApi = require('spotify-web-api-node')
const buddyList = require('spotify-buddylist')

const api = buddyList.wrapWebApi(new SpotifyWebApi({ spDcCookie }))

const tokenResponse = await api.getWebAccessToken()
api.setAccessToken(tokenResponse.body.accessToken)

const friendActivityResponse = await api.getFriendActivity()
const friendActivity = friendActivityResponse.body

Error printout is:
body: {},
headers: {
date: 'Thu, 17 Aug 2023 19:51:18 GMT',
'content-type': 'text/html; charset=utf-8',
vary: 'Accept-Encoding',
'content-encoding': 'gzip',
'x-envoy-upstream-service-time': '0',
'sp-trace-id': 'bb8a47291bedb1f1',
'strict-transport-security': 'max-age=31536000',
'x-content-type-options': 'nosniff',
server: 'envoy',
via: 'HTTP/2 edgeproxy, 1.1 google',
'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000',
connection: 'close',
'transfer-encoding': 'chunked'
},
statusCode: 403

@ironjaw72
Copy link
Author

I added this to index.js to accomplish what I wanted rather than using the wrapWebApi. It works well.

exports.getMyCurrentPlaybackState = async function getMyCurrentPlaybackState (webAccessToken) {

  const res = await fetch('https://api.spotify.com/v1/me/player', {
    headers: {
      Authorization: `Bearer ${webAccessToken}`
    }
  })
  
  if (res.status != 200) { return res.status }  

  return res.json()
}

exports.getMyCurrentPlayingTrack = async function getMyCurrentPlayingTrack (webAccessToken) {
  const res = await fetch('https://api.spotify.com/v1/me/player/currently-playing', {
    headers: {
      Authorization: `Bearer ${webAccessToken}`
    }
  })

  return res.json()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant