forslund / spotify-skill

Mycroft Skill to control spotify using the Spotify Connect API
Apache License 2.0
71 stars 38 forks source link

Cannot connect my spotify account #152

Open Lenteguppie opened 3 years ago

Lenteguppie commented 3 years ago

When I want to configure your Skill with my Spotify credentials I get an error page with the error: INVALID_CLIENT: Failed to get client. Am I doing something wrong?

forslund commented 3 years ago

Recently Spotify disabled the skill's API key so the skill can currently not be used. I'm trying to get through to Spotify to get this up and running again I'm also working on a workaround where users can supply their own key to the skill. got a POC on that but it'll require some more work to get it user friendly.

Lenteguppie commented 3 years ago

Ok, thanks! I am looking forward to it!

fermulator commented 3 years ago

same

The observation

Recently noticed:

 00:51:32.905 | INFO     |   712 | __main__:handle_utterance:72 | Utterance: ['play classical music on spotify']
 00:51:33.117 | INFO     |   706 | Playback Control Skill | Resolving Player for: classical music on spotify
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
Removing event mycroft-playback-control.mycroftai:PlayQueryTimeout
 00:51:40.423 | INFO     |   706 | Playback Control Skill | Playing with: mycroft-spotify.forslund
 00:51:40.696 | ERROR    |   706 | SpotifySkill | User info has been set but Auth failed.
 00:51:40.958 | INFO     |   706 | Playback Control Skill | Audio service status: {}

I confirmed my user/pass is correct in the config, so then retried the "Connect" button in the account skills https://account.mycroft.ai/skills

it punts me to something like: https://accounts.spotify.com/authorize?client_id=SNIP&redirect_uri=https%3A%2F%2Fapi.mycroft.ai%2Fv1%2Fauth%2Fcallback&scope=user-library-read+streaming+playlist-read-private+user-top-read+user-read-playback-state&state=SNIP&access_type=offline&response_type=code

browser shows: INVALID_CLIENT: Failed to get client

@forslund - per discussion;

System Versions

fermulator commented 3 years ago

What is a bit bonkers to me is:

  1. Google and Alexa do this ... did their systems get blocked too?
  2. https://developer.spotify.com/documentation/web-api/ specifically talks about how to achieve integration for develop "My App" ... hmmm
fermulator commented 3 years ago

Found: https://developer.spotify.com/terms/

Do not use the Spotify Platform, Spotify Content, Spotify Service, or Spotify Marks in any way to create a voice-enabled SDA that enables a user to control with his or her voice, or any kind of voice assistant that provides voice-control functionality without prior written authorization from Spotify.

fermulator commented 3 years ago

This sucks :cry: , we will try to go through official spotify channels to get this resolved.

Y0ngg4n commented 3 years ago

@fermulator any Updates from Spotify?

fermulator commented 3 years ago

Nothing yet;

  1. tried: https://developer.spotify.com/terms/#report-form-modal about a week ago
  2. seeing if I can find a colleague their to learn more about the process

@forslund indicated to me offline he contacted them as well (not sure by which method)

The other way I know of is: https://developer.spotify.com/support/

App Integration Application To build and distribute an application that using commercial integration, you must log in and create a client ID. You will be asked to fill in a form to submit an Application Integration Request.

But obviously this already went through that process? (@forslund can confirm) - but the application/request is so basic, I'm not sure how Spotify intends to approve or denote applications that REQUEST for written consent to have their application control Spotify via voice...

Y0ngg4n commented 3 years ago

Yes but same here with Deezer. Wrote them approximately 5 Emails and they sayed to me write them on twitter but no answer yet.

forslund commented 3 years ago

I started the "HW partner application" process, I also reached out through their Developer support (which I think is new) asking if there were some other channel to go through for this. They confirmed that it was the HW partner form that was needed. So it's the waiting game right now...

Y0ngg4n commented 3 years ago

@forslund ok thank you for your engagement ;)

0vermind commented 3 years ago

I fear only hardware partners with some kind of deal will be admitted. It is always a money game. Sad. p.s. In the old days, fake the client's ID was the solution but I suppose that there is some kind of cryptographic keys involved now. We can't tell everybody we are "Alexa". :P

forslund commented 3 years ago

Yes that's my fear as well. There is a branch which can use user supplied auth info, but I still need to write some docs on how to use it and make it smoother in case Spotify declines again.

Djinnxie commented 3 years ago

i cant figure out how to use my own key. is there a guide anywhere?

forslund commented 3 years ago

EDIT: this method has been added for now into the skill and instructions are available in the readme.md. I leave the old temporary instructions below for completeness but they should not be used anymore.

I quick (and quite dirty) but working way to run spotify with local auth

Set up a developer account and make sure to whitelist https://localhost:8888m then download spauth.py. Edit it with your client_id, secret and username

go to the mycroft-spotify skill directory and checkout the branch feature/local-api-key

git checkout feature/local-api-key

then in the mycroft-core dir run


pip install -r /opt/mycroft/skills/mycroft-spotify.forslund/requirements.txt

python spauth.py

this should result in a hidden file called .cache-USERNAME

now before starting Mycroft you need to put the client key and client secret in the environment variables

export SPOTIPY_CLIENT_ID=YOUR_CLIENT_ID
export SPOTIPY_CLIENT_SECRET=YOUR_CLIENT_SECRET

Then start Mycroft.

Sorry that I haven't had time to clean this procedure up...

georgefst commented 3 years ago

Thanks for the guide. Unfortunately that branch doesn't work for me:

 13:17:54.284 | ERROR    | 30275 | SpotifySkill | Couldn't fetch credentials
Traceback (most recent call last):
  File "/opt/mycroft/skills/mycroft-spotify.forslund/__init__.py", line 278, in load_local_creds
    scope=SCOPE)
TypeError: __init__() got an unexpected keyword argument 'username'

This is very odd, since the spotipy docs do show a username argument.

So presumably a versioning issue? I wish I could help, but Python's dependency management has always baffled me.

georgefst commented 3 years ago

Also, there's a step missing - you also need to whitelist https://localhost:8888 in the Spotify developer dashboard.

forslund commented 3 years ago

Ah humm, yes I think I've updated the spotipy dependency... try running ./bin/mycroft-pip install spotipy==2.14.0 from the mycroft-core folder.

Will add the whitelist step to the description. Thanks for flagging

georgefst commented 3 years ago

Works, awesome!

Would be a real shame if every user had to fiddle about with a developer account, but at least the option's there for now.

joshuajaharwood commented 3 years ago

Works, awesome!

Would be a real shame if every user had to fiddle about with a developer account, but at least the option's there for now.

It shouldn't be too bad once you can put your credentials in via Mycroft/Selene. Just a list of instructions to create the app appropriately and some copy-pasting would be needed.

jpvr555 commented 3 years ago

I was able to get it mostly working, I can get it to play and stop on other devices but not on the mycroft itself. Almost like it wasn't registered as a device at all.

forslund commented 3 years ago

The skill is not a player in itself, it requires a local player to be installed. Such as librespot or spotifyd (the player needs to be logged in and can't be in discovery mode)

jpvr555 commented 3 years ago

Oh thank you, I miss understood

joshuajaharwood commented 3 years ago

The skill is not a player in itself, it requires a local player to be installed. Such as librespot or spotifyd (the player needs to be logged in and can't be in discovery mode)

I couldn't see this on the README. May be worth mentioning if not already to prevent future tickets?

forslund commented 3 years ago

I have a PR I've forgotten to merge, sorry. It would be helpful if you could read through PR #145 and see if anything should be added

joshuajaharwood commented 3 years ago

I've left you some feedback on that PR!

Djinnxie commented 3 years ago

thanks for the update! i cant get it working though. i ran through your guide and it didnt work so i deleted .cache-USERNAME to try again. only now its saying "enter the URL you were redirected to" without giving me a url to enter. i tried unsetting my env variables and running the script in another directory as well as using the URL it provided me last time but no dice. i even tried making another app on the spotify dash. sorry for the trouble image

Asheboy commented 3 years ago

I'm in the same position as @Djinnxie and just receive the Enter the URL you were redirect to:. I think this is because the white-listing isn't working correctly, but I definitely have the URL set in the developer settings.

EDIT: It might be that spotipy doesn't support headless.

EDIT2: If you install links (sudo apt install links), then that will open the spotify authorisation URL automatically. I used ps aux | grep spotify to find the URL, opened it in a non-headless webbrowser, accepted the authorisation and then provided the URL I got redirected to.

forslund commented 3 years ago

Yeah it doesn't do headless it tries to launch a webbrowser. You can run it on a desktop and transfer the files to the target machine.

Thank's for the links tip as well!

goldyfruit commented 3 years ago

I was able to use the spauth.py script to generate the .cache-xxxxx file but now when I want to use the skill it says:

 19:16:56.187 | ERROR    | 13885 | SpotifySkill | User info has not been set.

I guess it's because the skill in https://home.mycroft.ai is not configured.

image

So I tried to generate the /home/pi/.config/mycroft/skills/mycroft-spotify.forslund/settings.json file with my user and password but still not working and at every restart the file is override.

EDIT1: By clicking on Save button, the /home/pi/.config/mycroft/skillIs/mycroft-spotify.forslund/settings.json file is correctly filled but now I got an authentication failure.

 20:40:08.923 | ERROR    | 17859 | SpotifySkill | User info has been set but Auth failed.
 >> Unable to authorize with the Spotify service. Please go to
    Skill settings at home dot mycroft dot ai to verify your
    username and password and to Connect to Spotify.

~~s:save_settings:113 | Skill settings successfully saved to /home/pi/.config/mycroft/skills/mycroft-spotify.forslund/settings.json
 20:45:55.882 | ERROR    | 17859 | SpotifySkill | Couldn't fetch credentials
Traceback (most recent call last):
  File "/opt/mycroft/skills/mycroft-spotify.forslund/__init__.py", line 278, in load_local_creds
    scope=SCOPE)
TypeError: __init__() got an unexpected keyword argument 'username'
 20:45:56.168 | INFO     | 17859 | SpotifySkill | Couldn't fetch credentials

EDIT2: As for @georgefst I had to downgrade the spotipy library to 2.14.0 (the 2.16.1 is installed by default).

$ pip install spotipy==2.14.0

All is working fine now.

forslund commented 3 years ago

Thanks for the update. I shall modify the spotipy version in the requirements.txt to match that. Then I'll merge the branch and update the instructions in the readme.

Thank you all for feedback and testing!

Next step will be to make this a bit easier to perform...

stic82 commented 3 years ago

It is not working for me. I am on Virtual Machine Ubuntu and after running First i run this command inside mycroft-core: ./bin/mycroft-pip install spotipy==2.14.0 than python spauth.py i get following error Message: Traceback (most recent call last): File "spauth.py", line 1, in import spotipy ImportError: No module named spotipy

forslund commented 3 years ago

@stic82 did you run the "source venv-activate.sh" part to enter the mycroft virtualenv?

stic82 commented 3 years ago

it was not virtualenv. That was the problem. Thank You!

erhan-ince commented 3 years ago

So far i set it up. Only problem left is that i can t setup the spotifyd part. So Mycroft says that theire is no device to play songs. After trying for 1.5 days i want to ask for some support :-)

buddens93 commented 3 years ago

Nice, thanks @forslund for the workaround!

Got it working but unfortunately it doesn't persist between reboots - I have to set the environment variables after restart or I get the credentials error.

What's the best way of setting these permanently?

georgefst commented 3 years ago

What's the best way of setting these permanently?

Set in one of ~/.bashrc, ~/.profile etc. Or prefix the command you use to start Mycroft e.g. SPOTIPY_CLIENT_ID=1234 SPOTIPY_CLIENT_SECRET=abcd ./mycroft-core/start-mycroft.sh.

buddens93 commented 3 years ago

What's the best way of setting these permanently?

Set in one of ~/.bashrc, ~/.profile etc. Or prefix the command you use to start Mycroft e.g. SPOTIPY_CLIENT_ID=1234 SPOTIPY_CLIENT_SECRET=abcd ./mycroft-core/start-mycroft.sh.

Awesome - cheers @georgefst. Using .profile didn't work but .bashrc did the trick!

forslund commented 3 years ago

You can also use the /etc/environment but then it will be available to all users

forslund commented 3 years ago

@erhan-ince Check the readme I've updated it after some awesome feed back from users here.

lilmike commented 3 years ago

I'm having trouble getting the cached credentials to work. I've tried placing .cache-username under the mycroft home directory, /usr/share/mycroft-core (the directory with .venv and other stuff in it), under /opt/mycroft/skills/mycroft-spotify, and a couple other places, all result in "Could not get spotify credentials". I don't have much debugging output either, since the skill catches any tracebacks and logs an error that isn't much use. Any help? I'm running on a raspberry pi running arch linux ARM, with the mycroft-core package from the arch user repository. Thanks! -Michael.

buddens93 commented 3 years ago

After having to nuke and re-install pycroft, i'm now trying to get this running again but having the same issues seen by @goldyfruit and @lilmike, but can't get it working:

ERROR | 653 | SpotifySkill | User info has been set but Auth failed.

I see the same errors so follow the steps outlined by @goldyfruit but unfortunately the issue persists even after downgrading spotipy, and there's no other error messages in skills.log...

@forslund Any suggestions? Thanks!

forslund commented 3 years ago

Hi @buddens93 Can you try to ask "what spotify devices are available" this should give us some indication of the state it is in.

buddens93 commented 3 years ago

Hi @forslund thanks for picking this up... "what spotify devices are available" results in the following:

 02:39:28.942 | INFO     |  1595 | SpotifySkill | <mycroft-spotify_forslund.spotify.SpotifyConnect object at 0x968698f0>
~~~~ipy.oauth2 | User authentication requires interaction with your web browser. Once you enter your credentials and give authorization, you will be redirected to a url.  Paste that url you were directed to to complete the authorization.
~~~~fy.com/authorize?client_id=a73496cc33954814bafc78898ab7b6eb&response_type=code&redirect_uri=https%3A%2F%2Flocalhost%3A8888&scope=playlist-read-private+streaming+user-library-read+user-read-playback-state+user-top-read in your browser
Enter the URL you were redirected to: 2021-01-16 02:39:28.955 | ERROR    |  1595 | mycroft-spotify_forslund.spotify:get_devices:80 | EOF when reading a line

I get a similar error message in the log when asking to play something now - along with a 'An error occurred while processing a request in Spotify Skill' from the TTS engine. I've re-installed and re-run the steps above a few times with the same result unfortunately...

Cheers

forslund commented 3 years ago

Ok that sounds like the crentials cache (.cache-USERNAME where USERNAME is your spotify username) isn't found...

can you check that the file exists and has content. This file needs to be in the folder from where Mycroft is launched. what platform are you on?

buddens93 commented 3 years ago

Yeah it's wierd...

.cache-USERNAME exists with the relevant info at ~/mycroft-core/skills/mycroft-spotify.forslund

Not sure if I'm doing something back to front in terms of process, but essentially I'm installing the skill (voice install) > enter credentials and preferences in skill settings at mycroft.ai (don't hit connect, only save) > run your workaround steps > have to re-enter credentials in skills settings again (otherwise 'user info has not been set' occurs) > downgrade spotipy (otherwise 'couldn't fetch credentials' occurs)

But I still hit the EOF error above...

I'm on a rpi 4 2gb - Buster Keaton - Pork Pi / mycroft-core: 20.8.0 ( master )

Thanks for your help!

forslund commented 3 years ago

~/mycroft-core/skills/mycroft-spotify.forslund doesn't sound right. It needs to be in the directory you are in when you're running start-mycroft.sh which would likely be ~/mycroft-core/

It's a bit weird, and I will be trying to make that a bit easier

buddens93 commented 3 years ago

Thanks @forslund !! All working now, appreciate the help 👍

My bad for missing this crucial bit for spauth.py:

then in the mycroft-core dir run

Cheers

mickenordin commented 3 years ago

I ran this on my laptop:

git clone https://github.com/forslund/spotify-skill/
git checkout feature/local-api-key
wget https://gist.githubusercontent.com/forslund/8a2045aaf7c1244d35920c67b3e22930/raw/9ca6931269126be1b1c447558b2d9c067c1b8685/spauth.py
pip install spotipy==2.14.0
~~python3 spauth.py

I am sure i did not need to have the skill on my laptop, but anyway, here we are :) After that I copied the resulting .cache-my_username file to /home/pi/mycroft-core/ on my raspberrypi and then I ran:

mycroft-msm install mycroft-spotify
mycroft-pip install spotipy==2.14.0
cd mycroft-core/skills/mycroft-spotify.forslund/
git checkout feature/local-api-key

I then added the environment variables to .bashrc. After that I rebooted but still I get:

 16:54:39.259 | INFO     |   682 | SpotifySkill | None
 16:54:39.261 | ERROR    |   682 | SpotifySkill | User info has not been set.

In the logfile and Mycroft sais:

I'm not connected to your Spotify account yet. Go to home dot mycroft dot   ai to setup your Spotify skill.

Edit: After adding my username and such to the skill config on home.mycroft.ai it seems I get no errors any more, but I still cant play anything. I get

 17:03:30.877 | INFO     |   681 | SpotifySkill | <mycroft-spotify_forslund.spotify.SpotifyConnect object at 0x852f4370>

And: There are no Spotify devices available. when I ask to list devices. I have several devices on my network including a working raspotify on the raspberrypi

Any pointers?

I actually does seem to work for me now. After playing some stuff from my phone on other devices, mycroft can see the ones I have used, but not the others. Strange, but it seems I am set now atleast.

forslund commented 3 years ago

It can only see logged in devices. so if the devices are set to be in discovery mode. After connecting to them using your phone they will be logged in.

What devices are you trying with?