Python spotipy.oauth2() Examples
The following are 5
code examples of spotipy.oauth2().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
spotipy
, or try the search function
.
Example #1
Source File: spotify.py From spotify-downloader with MIT License | 5 votes |
def _generate_token(self, client_id, client_secret): credentials = oauth2.SpotifyClientCredentials( client_secret=client_secret, ) token = credentials.get_access_token() return token
Example #2
Source File: spotify.py From spotify-downloader with MIT License | 5 votes |
def __init__(self, client_id=None, client_secret=None): global masterclient # `spotipy.Spotify` makes use of `self._session` and would # result in an error. The below line is a workaround. self._session = None credentials_provided = client_id is not None \ and client_secret is not None valid_input = credentials_provided or masterclient is not None if not valid_input: raise SpotifyAuthorizationError( "You must pass in client_id and client_secret to this method " "when authenticating for the first time." ) if masterclient: logger.debug("Reading cached master Spotify credentials.") # Use cached client instead of authorizing again # and thus wasting time. self.__dict__.update(masterclient.__dict__) else: logger.debug("Setting master Spotify credentials.") credential_manager = oauth2.SpotifyClientCredentials( client_id=client_id, client_secret=client_secret ) super().__init__(client_credentials_manager=credential_manager) # Cache current client masterclient = self
Example #3
Source File: pytifylib.py From Pytify with MIT License | 5 votes |
def getCredentials(self): try: return spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) except spotipy.oauth2.SpotifyOauthError: print('Did not find Spotify credentials.') print('Please visit https://github.com/bjarneo/pytify#credentials for more information.') sys.exit(1) # query
Example #4
Source File: spotify.py From Needl with MIT License | 5 votes |
def register(): client_id = needl.settings["spotify"]["client_id"] client_secret = needl.settings["spotify"]["client_secret"] if client_id and client_secret: os.environ["SPOTIPY_CLIENT_ID"] = client_id os.environ["SPOTIPY_CLIENT_SECRET"] = client_secret client_credentials_manager = spotipy.oauth2.SpotifyClientCredentials() global spotify_client spotify_client = spotipy.Spotify(client_credentials_manager=client_credentials_manager) search_interval = needl.settings['spotify']['search_interval'] args = map(int, search_interval.split('..')) needl.schedule.every(*args).minutes.do(search_artist)
Example #5
Source File: sensor.py From SmartHouse with MIT License | 5 votes |
def _load_token(self): try: import spotipy.oauth2 callback_url = '{}{}'.format(self.hass.config.api.base_url, AUTH_CALLBACK_PATH) cache = self.config.get(CONF_CACHE_PATH, self.hass.config.path(DEFAULT_CACHE_PATH)) self.oauth = spotipy.oauth2.SpotifyOAuth( self.config.get(CONF_CLIENT_ID), self.config.get(CONF_CLIENT_SECRET), callback_url, scope=SCOPE, cache_path=cache) self.token_info = self.oauth.get_cached_token() except Exception as e: LOGGER.error("Could not refresh token") LOGGER.error(e)