[Python] Spotify API token 생성

Denver·2023년 1월 1일
0

python

목록 보기
5/5
post-thumbnail

0. 실행 환경

Python : 3.9


1. 토큰 생성

import requests
import base64
import json

client_id = '<Client ID>'
client_secret = '<Client Secret>'
endpoint = 'https://accounts.spotify.com/api/token'


encoded = base64.b64encode(f'{client_id}:{client_secret}'.encode('utf-8')).decode('ascii')

headers = {'Authorization': f'Basic {encoded}'}
payload = {'grant_type': 'client_credentials'}

response = requests.post(endpoint, data=payload, headers=headers)
# print(json.loads(response.text))
access_token = json.loads(response.text)['access_token']
print(access_token)
profile
까먹었을 미래의 나를 위해

0개의 댓글