platypush/common/spotify/__init__.py
def spotify_api_authenticate(self):
        """
        Authenticate to the Spotify API for requests that don't require access to user data.
        """
        if not (self._spotify_api_token or self._spotify_user_token):
            self._spotify_load_user_credentials()

        self._spotify_assert_keys()
        if (self._spotify_user_token and self._spotify_user_token_expires_at > datetime.now()) or \
                (self._spotify_api_token and self._spotify_api_token_expires_at > datetime.now()):
            # Already authenticated
            return

        rs = requests.post(
            'https://accounts.spotify.com/api/token',
            headers={
                'Content-Type': 'application/x-www-form-urlencoded',
                **self._spotify_authorization_header(),
            },
            data={
                'grant_type': 'client_credentials',
            }
        )

        rs.raise_for_status()
        rs = rs.json()
        self._spotify_api_token = rs.get('access_token')
        self._spotify_api_token_expires_at = datetime.now() + timedelta(seconds=rs.get('expires_in'))

        Authenticate to the Spotify API for requests that don't require access to user data.
        
Authenticate to the Spotify API for requests that don't require access to user data.
Authenticate to the Spotify API for requests that don ' t require access to user data .
def spotify_api_authenticate(self):
        if not (self._spotify_api_token or self._spotify_user_token):
            self._spotify_load_user_credentials()
        self._spotify_assert_keys()
        if (self._spotify_user_token and self._spotify_user_token_expires_at > datetime.now()) or \
                (self._spotify_api_token and self._spotify_api_token_expires_at > datetime.now()):
            return
        rs = requests.post(
            'https://accounts.spotify.com/api/token',
            headers={
                'Content-Type': 'application/x-www-form-urlencoded',
                **self._spotify_authorization_header(),
            },
            data={
                'grant_type': 'client_credentials',
            }
        )
        rs.raise_for_status()
        rs = rs.json()
        self._spotify_api_token = rs.get('access_token')
        self._spotify_api_token_expires_at = datetime.now() + timedelta(seconds=rs.get('expires_in'))
def spotify_api_authenticate ( self ) : if not ( self . _spotify_api_token or self . _spotify_user_token ) : self . _spotify_load_user_credentials ( ) self . _spotify_assert_keys ( ) if ( self . _spotify_user_token and self . _spotify_user_token_expires_at > datetime . now ( ) ) or ( self . _spotify_api_token and self . _spotify_api_token_expires_at > datetime . now ( ) ) : return rs = requests . post ( 'https://accounts.spotify.com/api/token' , headers = { 'Content-Type' : 'application/x-www-form-urlencoded' , ** self . _spotify_authorization_header ( ) , } , data = { 'grant_type' : 'client_credentials' , } ) rs . raise_for_status ( ) rs = rs . json ( ) self . _spotify_api_token = rs . get ( 'access_token' ) self . _spotify_api_token_expires_at = datetime . now ( ) + timedelta ( seconds = rs . get ( 'expires_in' ) )
Authenticate to the Spotify API for requests that don't require access to user data.
Authenticate to the Spotify API for requests that don ' t require access to user data .
"""
        Authenticate to the Spotify API for requests that don't require access to user data.
        """ # Already authenticated
self