【发布时间】:2016-11-12 20:28:14
【问题描述】:
我一直在使用 Spotify API 编写一个 chrome 扩展程序,并且刚刚到了需要 OAUTH 来完成它的部分。
我一直在查看 spotify 誓言页面 (https://developer.spotify.com/web-api/authorization-guide/)
它说您只需进行 GET 调用,它就会将您带到登录页面,但是当我实现它时,它什么也不做。我觉得我错过了一些代码,但我不确定我错过了什么。
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
// Just alerting it to see what it came up with
alert(xhr.responseText);
}
}
xhr.open("GET", "https://accounts.spotify.com/authorize/?client_id=<clientID>&response_type=code&redirect_uri=https%3A%2F%2Fwww.google.com%2F", true);
xhr.send();
这就是我现在拥有的代码(填写了客户端 ID),运行它什么也不做。 (我现在指定http://www.google.com/ 作为我的回调)
【问题讨论】:
-
1.上面的代码在哪里?内容脚本或背景页面? 2、你有没有在
manifest.json声明对应的主机权限? -
是的,我设置了权限。并且代码在内容脚本中
标签: javascript html google-chrome google-chrome-extension oauth