I would like to scrape data using the Spotify API and I cannot seem to get the example curl command to translate to HTTP.jl
I am trying to get the accesstoken using my credentials. The relevant (working) curl command run through Julia is:
run(`curl -X "POST" -H "Authorization: Basic $refreshtoken" -d grant_type=client_credentials https://accounts.spotify.com/api/token -o creds.json`)
My attempt in HTTP.jl is:
HTTP.request("POST",
"https://accounts.spotify.com/api/token",
["Authorization" => "Basic: $refreshtoken"],
"grant_type=client_credentials")
# OR
HTTP.request("POST",
"https://accounts.spotify.com/api/token",
["Authorization" => "Basic $refreshtoken"],
"grant_type=client_credentials", status_exception=false)
However I get an error:
ERROR: HTTP.ExceptionRequest.StatusError(400, "POST", "/api/token", HTTP.Messages.Response:
"""
HTTP/1.1 400 Bad Request
date: Fri, 22 Jan 2021 17:06:19 GMT
content-type: text/html; charset=utf-8
Content-Length: 1015
...
"""
EDIT:
The following also works in python
import requests
out = requests.post("https://accounts.spotify.com/api/token",
{"grant_type":"client_credentials"},
headers={"Authorization": f"Basic {refreshtoken}"})
Help is much appreciated!