我无法从Spotify检索我的应用程序的访问令牌

问题描述:

我无法从Spotify获取Android应用程序的访问令牌,因为我可以连接到端点。

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

我需要我的Android应用程序的访问令牌我尝试了以下方法:
1)Spotify Android身份验证库。我找不到他们谈论的spotify-auth-version.aar。
2)手动构建网址。例如:

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

当我尝试连接时,我会遇到各种可能的错误:缺少必需的参数:client_id, INVALID_CLIENT:无效的重定向URI,找不到页面,甚至其他我都不记得了。我想问题出在redirect_uri上。因此,我添加了几个不同的重定向地址并尝试了所有重定向地址,但是什么都没有。

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.

这是我在应用程序中添加地址时的地址:
https://spotify_test.com/callback
http://marcoalunno.com/callback
http :// localhost:8888 / callback /
http://marcoalunno.com.spotify_test / callback

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

及其编码版本:
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

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

我知道很多人在*上询问 INVALID_CLIENT:无效的重定向URI,但我找不到一个结论性的答案,对此我感到非常沮丧。

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

据我所知, .aar 文件是将该库集成到项目中的一种旧方法,现在您只需要在 build.gradle 中添加以下行:

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'

更多信息和所需的进一步步骤可以在库中找到 GitHub页面

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

您对服务器上的重定向URI做了什么?我只是将 soundtrack:// callback 用于我的名为app的配乐。我想您可以使用几乎任何您喜欢的东西,只要它与您的Spotify开发人员仪表板和您的android应用清单文件中的匹配即可。

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.

借助与手动方式相比,Spotify Auth库应该更容易进行身份验证。如果您想采用手动方式,我可以研究一下url构建过程并相应地编辑此答案。

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.

spotify auth示例项目中的相关文件是:

The relevant files in the spotify auth sample project are:

  • build.gradle - where you add the auth library

spotify-strings.xml -在此声明清单文件的重定向方案和主机。在我的情况下 scheme =原声 host =回调

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

MainActivity.java -在其中创建请求并处理
响应。

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