Authorization¶
Note
Before you use HSpotipy, you have to set up your web server by yourself. After that, your users can access your server and log in to their Spotify account.
All content in this section can be found in Web API Tutorial - Beginner’s Tutorial .
Step 1 : Create Spotify App¶
Please follow Web API Tutorial to set up your account, register your application, get your client ID and Secret Key and set up your local website via JaveScript.
Set up Account and Application¶
- Set up your account : Spotify Developer Website
- Register your application : Spotify My Applications
- After registering your application, you can get and set your:
- Client ID
- Client Secret Key
- Redirect URL , to test locally, set to http://localhost:8888/callback
Try Web Service Environment¶
Mac OX Install node.js¶
Follow http://blog.teamtreehouse.com/install-node-js-npm-mac or simply enter:
Keep follow Web API Tutorial and Spotify Web API Authorization JaveScript Example to set up your web service environment.
Run OAuth example locally¶
Download OAuth examples, the code of the OAuth examples depends on the packages express,request and querystring. Download and install the dependencies running the following command.
To run the web example, open authorization_code/app.js
, set the Client ID, Client ID and Redirect URL as http://localhost:8888/callback.
.. code-block:: bash
cd authorization_code node app.js
Open http://localhost:8888 , the users can log in or sign up their account, just like how users do in Spotify website.
- User can now get the oAuth info
- Access token
- Refresh token
Step 2: Python¶
Open Spotipy Authorized requests .
- The
Authorization Code flow
This method is suitable for long-running applications which the user logs into once. It provides an access token that can be refreshed.- The
Client Credentials flow
The method makes it possible to authenticate your requests to the Spotify Web API and to obtain a higher rate limit than you would
Previous example just show how to use OAuth on web browser