【问题标题】:launchWebAuthFlow with Spotify returns "Authorization page could not be loaded"带有 Spotify 的 launchWebAuthFlow 返回“无法加载授权页面”
【发布时间】:2015-04-11 07:27:33
【问题描述】:

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

我还尝试用/provider_cb 切换/spotify

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.

【问题讨论】:

  • 尝试从权限 URL 中删除 /,使其变为 "https://accounts.spotify.com/authorize*"
  • 没有区别:(
  • 为什么将"/spotify" 附加到redirectUri?您可能想尝试不使用。此外,chrome.identity.getRedirectURL() 返回类似 hmjkmjkepdijhoojdojkdfohbdgmmhki.chromiumapp.org 的内容,因此您可能会遇到双斜杠问题。

标签: google-chrome google-chrome-extension spotify google-chrome-app spotify-app


【解决方案1】:

你可以使用

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

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

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

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

【讨论】:

    【解决方案2】:

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

    var redirectUri = chrome.identity.getRedirectURL('spotify')
    

    【讨论】:

      猜你喜欢
      • 2021-01-14
      • 2020-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 2018-09-22
      • 2014-08-13
      相关资源
      最近更新 更多