Skip to content

Instantly share code, notes, and snippets.

@chaudharypraveen98
Created July 2, 2021 11:06
Show Gist options
  • Save chaudharypraveen98/5a5480c242113264322baef38b69dd1e to your computer and use it in GitHub Desktop.
Save chaudharypraveen98/5a5480c242113264322baef38b69dd1e to your computer and use it in GitHub Desktop.
It is a class based api. It makes multiple get request with the spotify.

SpotifyApi

It is a class based api. It makes multiple get request with the spotify.

Web Preview

How to setup the Api :-

  1. First install requirements.txt by :- python3 install -r requirements.txt
  2. Enter the client id and secret key that you have get from the spotify developer account in the "spotify_api.py".
  3. Make a object of the class to use methods.
    Example:-
    spotify = SpotifyApi()
  4. Then you have to perform authentication for getting the access token. A access token is used to make get request. One need to understand that access token has a expiry time i.e 3600 seconds for version 1 now. But your class automatically manages that work for you. It will regenerate the token if expires. So you don't need to worry about it at all. Running authentication is one time process. For authentication simply run :-
    spotify.perform_auth()

How to use the Api:

  1. Now you can start using the methods or get requests as shown below :-
    spotify.search(query, operator=None, operator_query=None, search_type="type")
    where :-
    query = It can be anything depending on the type of search. For search type like artist, it can be Neha Kakkar, Honey Singh, Raaftar etc.
    search_type = spotify provides different type of searches like by artists, albums or tracks.
    operator = spotify provides two type of operator i.e "OR" and "NOT". NOT operator means exclude it. OR operator means anyone of both.
    operator_query = means anything you want to exclude or to make an option. example :-
    songs=spotify.search("Tony", operator="not" , operator_query="Kakkar", search_type="artist")
    The above code will search for tony but it will neglect the results which contains the Kakkar in their title.
  2. You can even search for the track in the similar way for track. Example :-
    spotify.search(Time, search_type="track")

Note : -
You can use this Spotify Api Client without any issue. Feel free to suggest changes.

Last Test : -
12 January 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment