mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hi glorious people of the forums. Ive been trying to mess around with a spotify-songrequest kind of thing and part of that is authorization. to obtain a refresh token (which are used to prevent access tokens from expiring) i need to POST to spotify's account server as explained on the 4th step of https://developer.spotify.com/web-api/authorization-guide/

basically they want you to add the body parameters 'grant_type' 'code' and 'redirect_url' and i have no idea how to do that.

so far i have this and its returning 500's
Code:
on *:sockopen:oauth: { 
  msg #sjoepele  [DEBUG] oauth initialized
  sockwrite -n $sockname POST /api/token HTTP/1.1
  sockwrite -n $sockname Host: accounts.spotify.com
  sockwrite -n $sockname Authorization: Basic <base64 encoded client secret:clientid censored>
  sockwrite -n $sockname Accept-Encoding: compress
  sockwrite -n $sockname Accept: application/json
  sockwrite -n $sockname Connection: close
  sockwrite -n $sockname 
  sockwrite -n $sockname grant_type=authorization_code
  sockwrite -n $sockname code= <authorization code censored>
  sockwrite -n $sockname redirect_uri=http://localhost/
}


tl;dr have to add body parameters and don't know how

If someone could help me out that would be greatly appreciated ^_^

Joined: Jan 2004
Posts: 1,358
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Jan 2004
Posts: 1,358
Code:
var %data = $+(grant_type=,%grant_type,&code=,%code,&redirect_url=,%redirect_url)

sockwrite -n $sockname Content-Type: application/x-www-form-urlencoded
sockwrite -n $sockname Content-Length: $len(%data)
sockwrite -n $sockname $+($crlf,%data)

Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Loki you are my hero blush

Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
Hmm now im trying to send JSON in the same way but
Code:
var %tracks = $+({ "tracks": [{ "uri": " $+ %delsong $+ " }] })

this returns
Code:
"status": 400,
"message": "JSON body does not adhere to the defined endpoint parameters: \"tracks\": [{ \"uri\": \"spotify:track:5eWgDlp3k6Tb5RD8690s6I\" }]"

mind that it doesnt show the opening bracket in the error description, which makes me think it dropped that for some reason and thinks its part of the code? So i tried using $chr(123) but this:

Code:
var %tracks = $+( $chr(123) "tracks": [{ "uri": " $+ %delsong $+ " }] })

returns 'malformed JSON Body'

I wonder whats the best way to go about this

Joined: Apr 2010
Posts: 969
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 969
what's the value of %delsong


I am SReject
My Stuff
Joined: Mar 2014
Posts: 42
S
Ameglian cow
OP Offline
Ameglian cow
S
Joined: Mar 2014
Posts: 42
a spotify ID, but i found the problem.
when i sent it to a testserver i noticed that it had dropped ALL the brackets :P So i changed stuff around a bit.

Code:
var %tracks = $+($chr(123) "tracks": [{ "uri": " $+ %delsong $+ " }] $chr(125))


now it looks like that, don't know why it works, but it does. Thanks though laugh


Link Copied to Clipboard