launchWebAuthFlow with Spotify returns “Authorization page could not be loaded”

匿名 (未验证) 提交于 2019-12-03 00:48:01

问题:

I registered my app on Spotify. I made sure I had the URI added to my registered app. But still every time I run this code I keep getting the same error. I am also running this in the background so I know it's not that. What am I doing wrong?

Also I tried switching /spotify with /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); }); 

Here are my permissions:

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

On the first time I run my app after restarting Chrome, the sign-in page pops up like everything is fine, but after I log in I still get the same error:

identity.launchWebAuthFlow: Authorization page could not be loaded. 

回答1:

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

should be

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

getRedirectUrl will return a url with a / at the end. so your original code was resulting in:

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!