brim-borium / spotify_sdk

Flutter Package to connect the spotify sdk
https://pub.dev/packages/spotify_sdk
Apache License 2.0
143 stars 81 forks source link

getAccessToken failed with: Authentication went wrong #196

Open Roman-Dzerkal opened 11 months ago

Roman-Dzerkal commented 11 months ago

Hello! Here is function that requests access token, trigerred by clicking on a button:

Future<void> getAccessToken() async {
    if (!dotenv.isEveryDefined(['CLIENT_ID', 'REDIRECT_URL'])) {
      throw Exception('There are no spotify credentials. Check your .env file');
    }

    final String spotifyClientId = dotenv.get('CLIENT_ID').toString();
    final String spotifyRedirectUri = dotenv.get('REDIRECT_URL').toString();

    try {
      accessToken = await SpotifySdk.getAccessToken(
          clientId: spotifyClientId, redirectUrl: spotifyRedirectUri);
    } catch (exception) {
      log(exception.toString());
    }
  }

After execution this code I get an error: изображение

Here the android folder structure изображение

The build.gradle file cointains next code:

configurations.maybeCreate("default")
artifacts.add("default", file('spotify-app-remote-release-0.8.0.aar'))

The settings.gradle file cointains next code:

include ':app'
include ':spotify-app-remote'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
def properties = new Properties()

assert localPropertiesFile.exists()
localPropertiesFile.withReader("UTF-8") { reader -> properties.load(reader) }

def flutterSdkPath = properties.getProperty("flutter.sdk")
assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
apply from: "$flutterSdkPath/packages/flutter_tools/gradle/app_plugin_loader.gradle"

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.10.6, on Microsoft Windows [Version 10.0.17763.4131], locale ru-UA)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.6.4)
[√] Android Studio (version 2022.3)
[√] IntelliJ IDEA Ultimate Edition (version 2023.1)
[√] VS Code (version 1.80.2)
[√] Connected device (3 available)
[√] Network resources

! Doctor found issues in 1 category.

flutter --version

Flutter 3.10.6 • channel stable • https://github.com/flutter/flutter.git
Framework • revision f468f3366c (3 weeks ago) • 2023-07-12 15:19:05 -0700
Engine • revision cdbeda788a
Tools • Dart 3.0.6 • DevTools 2.23.1

What do I do wrong?

TimHoogstrate commented 10 months ago

Dear @Roman-Dzerkal,

You can try to copy and past the url from your log into your browser. It gives an indication of the error. E.g. redirect url or possibly other errors. Those errors can be copied and pasted into google for further help.

Kind regards,

brim-borium commented 10 months ago

Hi @Roman-Dzerkal did you try it with the current example ? Also I just released a prerelease Version of the package. Can you give it a try with the example from the new Version (3.0.0-dev.1)?

Roman-Dzerkal commented 10 months ago

Hi @Roman-Dzerkal did you try it with the current example ? Also I just released a prerelease Version of the package. Can you give it a try with the example from the new Version (3.0.0-dev.1)?

Hello! I didn't try dev1 version. Once i test it i'll notify you

Roman-Dzerkal commented 9 months ago

@brim-borium hello! Sorry for long answer. Tested the current example and it doesn't work. I get the same error like in issue description

Roman-Dzerkal commented 9 months ago

Dear @Roman-Dzerkal,

You can try to copy and past the url from your log into your browser. It gives an indication of the error. E.g. redirect url or possibly other errors. Those errors can be copied and pasted into google for further help.

Kind regards,

изображение

devsideal commented 7 months ago
I/flutter ( 5288): │ #0   SpotifySdk._logException (package:spotify_sdk/spotify_sdk.dart:669:15)
I/flutter ( 5288): │ #1   SpotifySdk.getAccessToken (package:spotify_sdk/spotify_sdk.dart:131:7)
I/flutter ( 5288): ├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
I/flutter ( 5288): │ ⛔ getAccessToken failed with: Authentication went wrong
I/flutter ( 5288): │ ⛔ AUTHENTICATION_SERVICE_UNAVAILABLE

Needs any other things to run the given example?

TimHoogstrate commented 7 months ago

@devsideal,

Could this help?

This is clearly a native SDK issue. If you have searched a bit you would have come up with this issue. I suggest you follow it for any suggested solutions.

I have also come across this and just switching to a different client id solved the issue for me. In the majority of the cases (if not all) the error is the result of misconfiguration. Having said that, we can't provide with this level of support here. This is between you and Spotify. The best thing you can do is create a native Android sample app or use the official example app, with your credentials, and once it works then move to the Flutter SDK.

Closing...

_Originally posted by @fotiDim in https://github.com/brim-borium/spotify_sdk/issues/177#issuecomment-1482416769_

Mohamed-Abdulla commented 1 month ago

I'm having same issue, can someone help?

haashem commented 3 weeks ago

Any solution? me too.

iampawan commented 3 weeks ago

Same issue

banool commented 3 weeks ago

Unfortunately the maintainers don't have a whole lot of time to work on this, but are ofc happy to look at PRs!

haashem commented 3 weeks ago

I solved it ✅:

be sure to have added both debug and release fingerprint for Android in the Spotify developer portal:

https://developer.spotify.com/documentation/android/tutorials/application-fingerprints