简体   繁体   中英

Spotify API Curl request to Python Request

I'm currently trying to request an access token through the spotify API and am having trouble because the way the guide requests from the token endpoint is as such:

curl -H "Authorization: Basic ZjM...zE=" -d grant_type=authorization_code -d code=MQCbtKe...44KN -d redirect_uri=https%3A%2F%2Fwww.foo.com%2Fauth https://accounts.spotify.com/api/token

I'm instead trying to implement this solely in Python and am confused on how I would make this request using the requests library in Python. I've outlined what I think the request should look like:

r = requests.post("https://accounts.spotify.com/api/token", data = {}, auth = (client_id, client_secret))

But I am a little lost, any help would be appreciated!

You can visit this website . Your curl command looks like that in python:

import requests

headers = {
    'Authorization': 'Basic ZjM...zE=',
}

data = {
  'grant_type': 'authorization_code',
  'code': 'MQCbtKe...44KN',
  'redirect_uri': 'https://www.your_address.com/auth'
}

response = requests.post('https://accounts.spotify.com/api/token', headers=headers, data=data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM