initial commit with token refresh
This commit is contained in:
commit
89acfa98ef
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
env
|
||||||
|
__pycache__
|
6
main.py
Normal file
6
main.py
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import spotframework.net.auth as auth
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print('hello world')
|
||||||
|
auth.refreshToken()
|
||||||
|
|
0
spotframework/__init__.py
Normal file
0
spotframework/__init__.py
Normal file
0
spotframework/net/__init__.py
Normal file
0
spotframework/net/__init__.py
Normal file
23
spotframework/net/auth.py
Normal file
23
spotframework/net/auth.py
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import os
|
||||||
|
import requests
|
||||||
|
from base64 import b64encode
|
||||||
|
|
||||||
|
client_id = os.environ['SPOTCLIENT']
|
||||||
|
client_secret = os.environ['SPOTSECRET']
|
||||||
|
user_access_token = os.environ['SPOTACCESS']
|
||||||
|
user_refresh_token = os.environ['SPOTREFRESH']
|
||||||
|
|
||||||
|
#This sets up the https connection
|
||||||
|
#we need to base 64 encode it
|
||||||
|
#and then decode it to acsii as python 3 stores it as a byte string
|
||||||
|
def refreshToken():
|
||||||
|
|
||||||
|
idsecret = b64encode(bytes(client_id + ':' + client_secret, "utf-8")).decode("ascii")
|
||||||
|
headers = { 'Authorization' : 'Basic %s' % idsecret }
|
||||||
|
|
||||||
|
data = {"grant_type": "refresh_token", "refresh_token": user_refresh_token}
|
||||||
|
|
||||||
|
req = requests.post('https://accounts.spotify.com/api/token', data = data, headers = headers )
|
||||||
|
|
||||||
|
if req.status_code == 200:
|
||||||
|
user_access_token = req.json()['access_token']
|
Loading…
Reference in New Issue
Block a user