You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Deezer Native SDK OAuth认证时始终提示无效令牌问题

Troubleshooting "Invalid OAuth access token" with Deezer Native SDK

Hey Stefano, let's walk through why you're seeing that error and fix it step by step—this is a common gotcha with Deezer's OAuth flow!

The Core Issue: You're Using an Authorization Code, Not an Access Token

First off, the code=fr7d8cf7ef16ff4f3b250592154c402b you're grabbing from the redirect is not an access token—it's an authorization code. Deezer's OAuth2 process requires two key steps:

  1. User authorizes your app, and Deezer sends you this code to your redirect URI.
  2. You exchange this code for a valid access token using your app's secret key.

You're skipping step 2 and passing the code directly to dz_connect_set_access_token, which is why the SDK throws the "Invalid OAuth access token" error.

What to Do Next

1. Exchange the Authorization Code for an Access Token

Send a POST request to Deezer's token endpoint with these parameters:

  • app_id: Your app ID (281202, as in your auth URL)
  • secret: Your app's secret key (found in your Deezer Developer Dashboard)
  • code: The authorization code you received in the redirect
  • redirect_uri: Exact same value you used in the initial auth request (http://localhost:3625/deezer)

Here's an example using curl:

curl -X POST "https://connect.deezer.com/oauth/access_token.php" \
  -d "app_id=281202" \
  -d "secret=YOUR_APP_SECRET" \
  -d "code=fr7d8cf7ef16ff4f3b250592154c402b" \
  -d "redirect_uri=http://localhost:3625/deezer"

The response will look like this:

access_token=abc123xyz&expires=3600&uid=123456

Grab the access_token value here—that's what you need to pass to dz_connect_set_access_token.

2. Ensure You're Using Your App Secret

You mentioned not using the secret key—this is incorrect! The secret is mandatory for exchanging the code for an access token. Without it, Deezer can't verify that the request is coming from your app, so it won't issue a valid token.

3. Verify Redirect URI Consistency

Double-check that the redirect_uri in your initial auth request, your callback endpoint, and the token exchange request are exactly identical (including port number, trailing slashes, and HTTP/HTTPS). Deezer strictly validates this, even minor differences will cause issues.

4. Rule Out Device ID Conflicts (Lower Priority)

While it's less likely to be the root cause, if you're still having issues after fixing the above, you can test using a unique device ID for your Deezer SDK session to rule out conflicts with the NanoPlayer token. Reset the device ID in your app context before initializing the Deezer connection.

5. Confirm SDK Version Compatibility

Since you mentioned older issues might be outdated, make sure you're using the latest version of the Deezer Native SDK and cross-reference its documentation to ensure the OAuth flow hasn't changed (though the core code-to-token exchange is standard for Deezer).

Final Check

Once you have the real access token, pass it to dz_connect_set_access_token like this:

dz_connect_set_access_token(app_ctxt->dzconnect, NULL, NULL, "YOUR_REAL_ACCESS_TOKEN");

That should resolve the invalid token error. Let me know if you hit any snags with the token exchange step!

内容的提问来源于stack exchange,提问作者Ste

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:01:28