1

I can't get an access token for my Android app from Spotify because I can connect to the end point.

I need the access token of my Android app and I tried the following: 1) Spotify Android auth library. I can't find the spotify-auth-version.aar they talk about. 2) building manually the url. Here is an example:

https://accounts.spotify.com/authorize?
client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxx&
response_type=code&
redirect_uri=http%3A%2F%2Fmarcoalunno.com.spotify_test%2Fcallback&
scope=playlist-read-private&
state=34fFs29kd09

When I try to connect I get every possible kind of error: "Missing required parameter: client_id", "INVALID_CLIENT: Invalid redirect URI", "Page not found", and even other I don't remember. I suppose that the problem is with the redirect_uri. So, I added several different redirect address and tried all of them, but nothing.

Here are my addresses as I added them in my app: https://spotify_test.com/callback http://marcoalunno.com/callback http://localhost:8888/callback/ http://marcoalunno.com.spotify_test/callback

and their encoded versions: https%3A%2F%2Fspotify_test.com%2Fcallback%0A http%3A%2F%2Fmarcoalunno.com%2Fcallback%0A http%3A%2F%2Flocalhost%3A8888%2Fcallback%2F%0A http%3A%2F%2Fmarcoalunno.com.spotify_test%2Fcallback

I know that many people asked about "INVALID_CLIENT: Invalid redirect URI" on Stackoverflow, but I couldn't find a conclusive answer and I'm getting seriously frustrated with this.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Marco
  • 35
  • 1
  • 7

1 Answers1

1

As far as I know the .aar file is an old way to integrate this library to your project and now you only need to add the following line to your build.gradle:

compile 'com.spotify.android:auth:1.1.0'

More information and required further steps can be found on the libraries GitHub page.

Do you do something with the redirect URI on your server? I just used soundtrack://callback for my soundtrack named app. I guess you can use almost whatever you like as long as this matches the ones in your Spotify developer dashboard and in your manifest file of your android app.

With the help of the Spotify Auth library it should be easier to authenticate compared to the manual way. If you want to pursue the manual way, I can take a look into the url building process and edit this answer accordingly.

The relevant files in the spotify auth sample project are:

  • build.gradle - where you add the auth library

  • spotify-strings.xml - where you declare the redirect scheme and host for the manifest file. In my case scheme = "soundtrack" host = "callback"

  • MainActivity.java - where you create the request and handle the response.

tomaculum
  • 547
  • 4
  • 15
  • 1
    No success. I started from scratch with another app in my Dashboard. I implemented the auth-sample from the android-auth-master library and all I get is Access Token: null and Request Code: null. I tried again manually and all I get is This site can’t be reached. I can never pass the login page and get at the Terms and Conditions of Use as shown in this video at 13:30: https://www.youtube.com/watch?v=ZvGnvOShStI&t=575s. I'm obviously doing something wrong but I don't know what and I don't know what else to try. – Marco Apr 26 '19 at 21:33
  • 1
    Alright, I have created a project with the mentioned steps above: [github project](https://github.com/tomaculum/spotifyplaylist-android). The required steps to make this work are in comments in the MainActivity.java. I've included the playlist list you mentioned in the other question as verification if the obtained access token works as expected. If there is something unclear, just ask – tomaculum Apr 27 '19 at 02:15
  • 1
    Thanks sooo much! this works and should be considered the right answer. Still no very clear to me why this works and mine not, but it's great. Now I need to get the tracks' names in my playlist, which is why I needed to get the access token in the first place. Can you help with this, too? – Marco Apr 27 '19 at 23:22
  • 1
    Got it. Found at https://stackoverflow.com/questions/52802015/cant-get-playlists-tracks-with-kaaels-spotify-web-api – Marco Apr 28 '19 at 01:49
  • 1
    Glad this worked finally! (: If this helped, please mark my answer as accepted and do so in your previous question since you used the suggested code in this project as well. – tomaculum Apr 29 '19 at 07:39
  • @tomaculum thank you so much for the sample project, was about 10x better than the official spotify documentation! – nmu Oct 19 '19 at 18:01