7

我在 Spotify 上注册了我的应用程序。我确保已将 URI 添加到我注册的应用程序中。但是每次我运行这段代码时,我都会遇到同样的错误。我也在后台运行它,所以我知道不是这样。我究竟做错了什么?

我也尝试/spotify/provider_cb.

var client_id = '<my_client_id>';
var redirectUri = chrome.identity.getRedirectURL() + "/spotify";

chrome.identity.launchWebAuthFlow({
  "url": "https://accounts.spotify.com/authorize?client_id="+client_id+
         "&redirect_uri="+ encodeURIComponent(redirectUri) + 
         "&response_type=token", 
  'interactive': true,  
},
function(redirect_url) { 
  console.log(redirect_url);
});

这是我的权限:

"permissions": [
  "http://*/*", "tabs", "webNavigation", "activeTab", "storage", "identity",
  "declarativeContent", "https://accounts.spotify.com/*",  
  "https://accounts.spotify.com/authorize/*"
]

在重新启动 Chrome 后第一次运行我的应用程序时,会弹出登录页面,好像一切都很好,但在我登录后我仍然收到相同的错误:

identity.launchWebAuthFlow: Authorization page could not be loaded.
4

2 回答 2

9

您可以使用

var redirectUri = chrome.identity.getRedirectURL("spotify");

getRedirectUrl将返回一个以 / 结尾的 url。所以你的原始代码导致:

"https://<app_id>.chromiumapp.org//spotify"

相反,您可以将端点作为参数传递给形成 url

于 2015-02-11T08:39:53.463 回答
1

getRedirectURL方法具有路径重载,因此您无需添加字符串。

var redirectUri = chrome.identity.getRedirectURL('spotify')
于 2019-07-13T00:03:07.367 回答