我想在手机上创建自己的(非商业)DDR应用程序,以便使用Spotify音乐进行娱乐。
到目前为止,我已经尝试遵循快速入门教程:https://developer.spotify.com/documentation/android/quick-start/
我已安装了Spotify应用,并且已使用高级帐户登录。
我去了Spotify开发人员仪表板并注册了我的应用程序。我的应用暂时称为MyDDR。
我将重定向URI设置为192.168.1.23:5000/callback
,这是在我的PC上运行的烧瓶服务器。我对其进行了测试,并且手机可以连接到它。我不知道这是否相关,因为目前我的代码没有触发流量。
然后,我将指纹和程序包名称添加到我在Spotify开发人员仪表板中注册的应用程序中。这是我的结果:
我创建了一个签名的捆绑包,其中包含一个根据this教程创建的密钥库。 我只做过“注册应用程序指纹”部分,因为该页面似乎只是我已经关注的快速入门指南的旧版本。
运行gradle任务signingReport
通过手动检查显示了与我的密钥库中相同的SHA1密钥。
> Task :app:signingReport
Variant: release
Config: none
----------
Variant: debug
Config: debug
Store: C:\Users\[name]\.android\debug.keystore
Alias: AndroidDebugKey
MD5: [removed]
SHA1: [mysha1key]
SHA-256: [removed]
Valid until: Wednesday, 8 September 2049
----------
[3 other variants, debugUnitTest, debugAndroidTest, releaseUnitTest]
我对签署应用程序不熟悉,因此我不确定它是否正确。 据我了解,我只需要关心调试吧?我没有计划将其发布到Play商店。
如您所见,我的包裹名称是com.example.myddr
spotify-app-remote-release-0.6.3.aar
文件并将其添加为新模块,从而下载了Spotify Android SDK。我将模块/项目与gson一起添加到了build.gradle(Module:app)依赖项中,就像指导的教程一样。dependencies {
implementation project(':spotify-app-remote')
implementation "com.google.code.gson:gson:2.8.5"
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
这是到目前为止的代码
package com.example.myddr;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import com.spotify.android.appremote.api.ConnectionParams;
import com.spotify.android.appremote.api.Connector;
import com.spotify.android.appremote.api.SpotifyAppRemote;
import com.spotify.protocol.client.Subscription;
import com.spotify.protocol.types.PlayerState;
import com.spotify.protocol.types.Track;
public class MainActivity extends AppCompatActivity {
private static final String CLIENT_ID = "2d6a5307b3024e7b9b32d52146150986";
private static final String REDIRECT_URI = "http://192.168.1.23:5000/callback";
private SpotifyAppRemote mSpotifyAppRemote;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
super.onStart();
ConnectionParams connectionParams =
new ConnectionParams.Builder(CLIENT_ID)
.setRedirectUri(REDIRECT_URI)
.showAuthView(true)
.build();
SpotifyAppRemote.connect(this, connectionParams,
new Connector.ConnectionListener() {
public void onConnected(SpotifyAppRemote spotifyAppRemote) {
mSpotifyAppRemote = spotifyAppRemote;
Log.d("MainActivity", "Connected! Yay!");
// Now you can start interacting with App Remote
connected();
}
public void onFailure(Throwable throwable) {
Log.e("MainActivity", throwable.getMessage(), throwable);
// Something went wrong when attempting to connect! Handle errors here
}
});
}
private void connected() {
}
}
但是在运行此程序时,我会收到很多这样的警告:
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/HelloDetails; annotation class 28
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/HelloDetails; annotation class 31
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/Info; annotation class 28
W/m.example.mydd: Unable to resolve Lcom/spotify/protocol/types/Info; annotation class 31
最后是一个错误:
E/MainActivity: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
com.spotify.android.appremote.api.error.AuthenticationFailedException: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
at com.spotify.android.appremote.api.LocalConnector.asAppRemoteException(LocalConnector.java:131)
at com.spotify.android.appremote.api.LocalConnector.access$000(LocalConnector.java:35)
at com.spotify.android.appremote.api.LocalConnector$1.onConnectionFailed(LocalConnector.java:111)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:142)
at com.spotify.android.appremote.internal.SdkRemoteClientConnector$ConnectionTask.onPostExecute(SdkRemoteClientConnector.java:75)
at android.os.AsyncTask.finish(AsyncTask.java:695)
at android.os.AsyncTask.access$600(AsyncTask.java:180)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: com.spotify.protocol.client.error.RemoteClientException: {"message":"com.spotify.mobile.android.spotlets.appprotocol.model.AppProtocol$Message"}
at com.spotify.protocol.client.RemoteWampClient.getRemoteClientException(RemoteWampClient.java:139)
at com.spotify.protocol.client.RemoteWampClient.access$200(RemoteWampClient.java:16)
at com.spotify.protocol.client.RemoteWampClient$1.onAbort(RemoteWampClient.java:44)
at com.spotify.protocol.client.WampRouterImpl.routeAbort(WampRouterImpl.java:100)
at com.spotify.protocol.client.WampRouterImpl.route(WampRouterImpl.java:26)
at com.spotify.protocol.client.AppProtocolCommunicator.onData(AppProtocolCommunicator.java:78)
at com.spotify.android.appremote.internal.RemoteServiceIo.handleMessage(RemoteServiceIo.java:113)
at com.spotify.android.appremote.internal.RemoteServiceIo.access$000(RemoteServiceIo.java:47)
at com.spotify.android.appremote.internal.RemoteServiceIo$IncomingHandler.handleMessage(RemoteServiceIo.java:91)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:537)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
此错误意味着由于AuthenticationFailedException,我无法连接到Spotify。搜寻错误无法提供令人满意的解决方案。我只找到忘记注册指纹的人,但是据我所知我已经这样做了。但是我也怀疑我没有正确地做,因为它看起来相当复杂。