spotify / web-api-examples

Basic examples to authenticate and fetch data using the Spotify Web API
Apache License 2.0
1.99k stars 1.67k forks source link

Error - 'Something' went wrong #10

Open patalanov opened 8 years ago

patalanov commented 8 years ago

I'm having a hard time trying to authenticate my spotify app on localhost. I have my redirect_uri set as localhost:8888/callback (have also tried it with http://)at my developer account, but I get this error page when terminal prompts me to enter the URL I'm being redirected to.

I am running my server using python -m SimpleHTTPServer 8888, and entering at terminal python script.py username.

this is my python script:

scope = 'user-library-read'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope, client_id='myId', client_secret='mySecret', **redirect_uri='localhost:8888/callback'**)

if token:
    sp = spotipy.Spotify(auth=token)
    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print track['name'] + ' - ' + track['artists'][0]['name']
else:
    print "Can't get token for", username

what could be wrong? please help

JMPerez commented 8 years ago

Hi @patalanov! I'm not sure this is the best project to ask for support. I think Spotipy would give you a better chance.

I can give it a try though. Do you know what URL is being requested when you see that Error - 'Something' went wrong?

patalanov commented 8 years ago

Hi! When I run the script on terminal, browser opens a tab, and I get this (terminal):

 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.

Opening https://accounts.spotify.com/authorize?scope=user-library-read&redirect_uri=localhost%3A8888%2Fcallback&response_type=code&client_id=my_id in your browser

Enter the URL you were redirected to: 

thanks

JMPerez commented 8 years ago

First thing I notice is that you need to add http:// in front of your redirect_uri. Then, if you haven't changed the client_id, you need to change it to the one you have obtained when created your application on the developer site.

patalanov commented 8 years ago

I've tried it both ways, Pérez...with and without http://, and have changed it accordingly both in the script and on developer site, saving the changes... and I have the client_id obtained... I just ommited it for security reasons..

Sent from my iPhone

On May 18, 2016, at 7:22 PM, José Manuel Pérez notifications@github.com wrote:

First thing I notice is that you need to add http:// in front of your redirect_uri. Then, if you haven't changed the client_id, you need to change it to the one you have obtained when created your application on the developer site.

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

JMPerez commented 8 years ago

Here's what we can do to troubleshoot this:

  1. Make sure your server is listening in that redirect_uri. You can curl http://localhost:8888/callback or try to access it from a browser. Add some log message and see if it is printed when accessing that URL.
  2. As a way to find out if your redirect_uri is set up correctly, you could follow the steps in the Web API Tutorial. Put in your app credentials and redirect_uri and run the project. You might be interested in testing the authorization code flow. If everything works, then the problem is in your Python code.
  3. As the last resource, I encourage you to move this issue to the Spotipy project and get some help there. I'm not familiar with that wrapper nor Python, so I can't be very helpful.
Pau1fitz commented 8 years ago

@JMPerez I a believe the issue is that you also need to add the callbackURI to your My Application, as well as the server side code. The tutorial doesn't make that too clear. do you accept PR to update the documentation slightly?

JMPerez commented 8 years ago

@Pau1fitz sure, PRs are more than welcome!