发现身份验证失败

时间:2016-09-29 16:01:59

标签: java android authentication spotify

我正在关注android sdk beta22-noconnect-2.20b上的Spotify教程,以便在我想要编写的应用程序上获得基础,而我无法让我的应用程序进行身份验证。我确信我已经签署了我的应用并将正确的指纹插入到"我的应用程序" spotify上的标签。我的URI是正确的。我也很确定我已经100%正确地遵循了教程。每次运行程序时都会出现此错误。

  

I / OpenGLRenderer:初始化的EGL,版本1.4

     

D / OpenGLRenderer:交换行为1

     

D / com.spotify.sdk.android.authentication.LoginActivity:https://accounts.spotify.com/authorize?client_id=7c59d84c8b7f4e35b3c85a7a5289db1b&response_type=token&redirect_uri=spotifymixer%3A%2F%2Fcallback&show_dialog=true&scope=user-read-private%20streaming

     

D / SpotifyAuthHandler:开始

     

D / com.spotify.sdk.android.authentication.LoginActivity:验证错误

     

D / SpotifyAuthHandler:停止

我不知道如何继续。我可以在程序中使用错误的签名吗?

我的MainActivity.java:

package com.example.mammo.spotifyplayer;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.View;


import com.spotify.sdk.android.authentication.AuthenticationClient;
import com.spotify.sdk.android.authentication.AuthenticationRequest;
import com.spotify.sdk.android.authentication.AuthenticationResponse;
import com.spotify.sdk.android.player.Config;
import com.spotify.sdk.android.player.ConnectionStateCallback;
import com.spotify.sdk.android.player.Error;
import com.spotify.sdk.android.player.Player;
import com.spotify.sdk.android.player.PlayerEvent;
import com.spotify.sdk.android.player.Spotify;
import com.spotify.sdk.android.player.SpotifyPlayer;

public class MainActivity extends Activity implements
    SpotifyPlayer.NotificationCallback, ConnectionStateCallback
{

    // TODO: Replace with your client ID
    private static final String CLIENT_ID = "7c59d84c8b7f4e35b3c85a7a5289db1b";
    // TODO: Replace with your redirect URI
    private static final String REDIRECT_URI = "spotifymixer://callback";

    private Player mPlayer;
    private static final int REQUEST_CODE = 1337;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI);

    builder.setScopes(new String[]{"user-read-private", "streaming"});
    AuthenticationRequest request = builder.build();

    AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);
}

public void tryAgain(View view){
    AuthenticationRequest.Builder builder = new AuthenticationRequest.Builder(CLIENT_ID, AuthenticationResponse.Type.TOKEN, REDIRECT_URI);

    builder.setScopes(new String[]{"user-read-private", "streaming"});
    AuthenticationRequest request = builder.build();

    AuthenticationClient.openLoginActivity(this, REQUEST_CODE, request);

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);

    if(requestCode == REQUEST_CODE){
        AuthenticationResponse response = AuthenticationClient.getResponse(resultCode, intent);
        if(response.getType() == AuthenticationResponse.Type.TOKEN) {
            Config playerConfig = new Config(this, response.getAccessToken(), CLIENT_ID);
            Spotify.getPlayer(playerConfig, this, new SpotifyPlayer.InitializationObserver() {

                @Override
                public void onInitialized(SpotifyPlayer spotifyPlayer) {
                    mPlayer = spotifyPlayer;
                    mPlayer.addConnectionStateCallback(MainActivity.this);
                    mPlayer.addNotificationCallback(MainActivity.this);
                }

                @Override
                public void onError(Throwable throwable) {
                    Log.e("MainActivity", "Could not initialize player: " + throwable.getMessage());
                }
            });
        }
    }
}

@Override
protected void onDestroy() {
    Spotify.destroyPlayer(this);
    super.onDestroy();
}

@Override
public void onPlaybackEvent(PlayerEvent playerEvent) {
    Log.d("MainActivity", "Playback event received: " + playerEvent.name());
    switch (playerEvent) {
        // Handle event type as necessary
        default:
            break;
    }
}

@Override
public void onPlaybackError(Error error) {
    Log.d("MainActivity", "Playback error received: " + error.name());
    switch (error) {
        // Handle error type as necessary
        default:
            break;
    }
}

@Override
public void onLoggedIn() {
    Log.d("MainActivity", "User logged in");

    mPlayer.playUri(null, "spotify:track:2TpxZ7JUBn3uw46aR7qd6V", 0, 0);
}

@Override
public void onLoggedOut() {
    Log.d("MainActivity", "User logged out");
}

@Override
public void onLoginFailed(int i) {
    Log.d("MainActivity", "Login failed");
}

@Override
public void onTemporaryError() {
    Log.d("MainActivity", "Temporary error occurred");
}

@Override
public void onConnectionMessage(String message) {
    Log.d("MainActivity", "Received connection message: " + message);
}


}

我的build.gradle(模块:app):

apply plugin: 'com.android.application'


android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
    applicationId "com.example.mammo.spotifyplayer"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

repositories {
mavenCentral()
flatDir {
    dirs 'libs'
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2',  {
    exclude group: 'com.android.support', module: 'support-annotations'
})
// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:beta22-noconnect-2.20b@aar'

// This library handles music playback
compile 'com.spotify.sdk:spotify-player:beta22-noconnect-2.20b@aar'
compile 'com.android.support:appcompat-v7:24.2.1'
testCompile 'junit:junit:4.12'
}

我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mammo.spotifyplayer">
<uses-permission android:name="android.permission.INTERNET"/>
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
    <!-- Needed for LoginActivity to work -->
    <activity
        android:name="com.spotify.sdk.android.authentication.LoginActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
</application>

</manifest>

0 个答案:

没有答案