Announcements

Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

User authenication with python

Solved!

User authenication with python

 

I tried to make a user authentication using python scripts. 

First I retrieve the auth_headers:

auth_headers = {
"client_id": client_id,
"response_type": "code",
"redirect_uri": "http://localhost:7777/callback",
"scope": "user-library-read"
}

r = webbrowser.open("https://accounts.spotify.com/authorize?" + urlencode(auth_headers))

 

Then I get the code from the callback url "code=..."

code = "...."

encoded_credentials = base64.b64encode(client_id.encode() + b':' + client_secret.encode()).decode("utf-8")

token_headers = {
"Authorization": "Basic " + encoded_credentials,
"Content-Type": "application/x-www-form-urlencoded"
}

token_data = {
"grant_type": "authorization_code",
"code": code,
"redirect_uri": "http://localhost:7777/callback"
}

r = requests.post("https://accounts.spotify.com/api/token", data=token_data, headers=token_headers)

 

 

So my problem is I have to run the first script to get the authorization code whenever I refresh. Is there anyway to automate this process? Thank you so much

Reply

Accepted Solutions
Marked as solution

Okay, maybe this answer on Stack Overflow can help you?

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

View solution in original post

4 Replies

With the Python module SpotiPy (GitHub | Documentation).

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

Thank you for your suggestion. I have already used it for a while, but I am trying to write my own request using plain python for studying purpose so I am looking for a pure python way instead.

Marked as solution

Okay, maybe this answer on Stack Overflow can help you?

XimzendSpotify Star
Help others find this answer and click "Accept as Solution".
If you appreciate my answer, maybe give me a Like.
Note: I'm not a Spotify employee.

I think this is what im looking for, thank you so much

Suggested posts

Type a product name