From e5c9fb42b123c3fc45b67098b00adc22d87b128d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 2 Jan 2023 20:33:14 -0800 Subject: fix: new bearer method --- rubys_song_skipper/api.py | 3 +-- rubys_song_skipper/spotify.py | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/rubys_song_skipper/api.py b/rubys_song_skipper/api.py index 63f50b8..63f8e79 100644 --- a/rubys_song_skipper/api.py +++ b/rubys_song_skipper/api.py @@ -2,7 +2,6 @@ import spotify from flask import Flask, redirect, request import threading - app = Flask(__name__) @@ -23,7 +22,7 @@ def login(): @app.route("/callback") def callback(): with open("code.txt", "w") as file: - file.write(request.args.get("code")) + file.write(spotify.bearer(request.args.get("code"))[0]) file.close() return ( diff --git a/rubys_song_skipper/spotify.py b/rubys_song_skipper/spotify.py index 3a9580f..96b09d5 100644 --- a/rubys_song_skipper/spotify.py +++ b/rubys_song_skipper/spotify.py @@ -6,15 +6,30 @@ CLIENT_ID = "3b278200b722431488a0e70111700211" CLIENT_SECRET = "0689cf819adb442a9abddce154f58cad" -def bearer(): - return requests.post( +def bearer(code): + token = requests.post( "https://accounts.spotify.com/api/token", + # data={ + # "grant_type": "client_credentials", + # "client_id": CLIENT_ID, + # "client_secret": CLIENT_SECRET, + # }, + headers={ + "Authorization": "", + "Accept": "application/json", + "Content-Type": "application/x-www-form-urlencoded", + }, data={ - "grant_type": "client_credentials", - "client_id": CLIENT_ID, - "client_secret": CLIENT_SECRET, + "grant_type": "authorization_code", + "code": code, + "redirect_uri": "https://rss.rubyyyrl.twitch.fuwn.lol/callback", }, - ).json() + ) + + if token.status_code == 200: + return (token["access_token"], token["refresh_token"], token["expires_in"]) + else: + return None def redirect_uri(): -- cgit v1.2.3