diff --git a/mopidy_iris/core.py b/mopidy_iris/core.py index 53d3a2de..616cda88 100755 --- a/mopidy_iris/core.py +++ b/mopidy_iris/core.py @@ -445,12 +445,25 @@ class IrisCore(object): } def refresh_spotify_token(self, data): - - url = 'https://accounts.spotify.com/api/token' - authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY=' + ## TODO: See if we can use the credentials used by Mopidy-Spotify 3.1.0 + # Currently this returns 'invalid_client' error + + # Use client_id and client_secret from config + # This was introduced in Mopidy-Spotify 3.1.0 + #if 'spotify' in self.config and 'client_id' in self.config['spotify']: + # authorization = str(self.config['spotify']['client_id']+':'+self.config['spotify']['client_secret']) + # authorization = authorization.encode('base64').replace('\n', '') + + # Mopidy-Spotify is old version, so just use basic authorization code + #else: + # authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY=' + + authorization = 'YTg3ZmI0ZGJlZDMwNDc1YjhjZWMzODUyM2RmZjUzZTI6ZDdjODlkMDc1M2VmNDA2OGJiYTE2NzhjNmNmMjZlZDY=' + url = 'https://accounts.spotify.com/api/token' headers = {'Authorization' : 'Basic ' + authorization} data = {'grant_type': 'client_credentials'} + data_encoded = urllib.urlencode( data ) req = urllib2.Request(url, data_encoded, headers) @@ -465,5 +478,12 @@ class IrisCore(object): }) return self.get_spotify_token({}) + except urllib2.HTTPError as e: - return e + error = json.loads(e.read()) + + return { + 'type': 'error', + 'message': 'Could not refresh token: '+error['error'], + 'source': 'refresh_spotify_token' + } diff --git a/src/js/views/Debug.js b/src/js/views/Debug.js index 350fb4ce..b35f20e1 100755 --- a/src/js/views/Debug.js +++ b/src/js/views/Debug.js @@ -25,7 +25,7 @@ class Debug extends React.Component{ this.state = { mopidy_call: 'playlists.asList', mopidy_data: '{}', - pusher_data: '{"method":"broadcast","data":{"type":"browser_notification","title":"Testing","body":"This is my message"}}' + pusher_data: '{"method":"get_config"}' } } @@ -151,6 +151,22 @@ class Debug extends React.Component{