diff options
| author | Fuwn <[email protected]> | 2023-01-02 20:33:14 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-01-02 20:33:14 -0800 |
| commit | e5c9fb42b123c3fc45b67098b00adc22d87b128d (patch) | |
| tree | 1fac616ea769be4a486da306ce0c07aeec55344f | |
| parent | feat(bot.py): debug code (diff) | |
| download | rubys_song_skipper-e5c9fb42b123c3fc45b67098b00adc22d87b128d.tar.xz rubys_song_skipper-e5c9fb42b123c3fc45b67098b00adc22d87b128d.zip | |
fix: new bearer method
| -rw-r--r-- | rubys_song_skipper/api.py | 3 | ||||
| -rw-r--r-- | 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(): |