【发布时间】:2017-09-19 20:50:10
【问题描述】:
尝试使用 Deezer JS SDK 访问 /user/me 时,我不断收到错误代码 300(无效的 OAuth 访问令牌)。我的代码大部分是从示例中复制的,所以我无法弄清楚为什么会发生这种情况。我尝试在 API 调用中手动指定令牌,并通过 HTTP 直接访问 API,并且没有通过 Invalid Access Token 错误。我做错了什么?
index.html:
<!doctype html>
<html>
<body>
<div id="dz-root"></div>
<a href="#" id="dtest">Login</a>
<a href="#" id="lstat">Get Login Status</a>
<a href="#" id="getme">Me</a>
<script type="text/javascript" src="http://cdn-files.deezer.com/js/min/dz.js"></script>
<script src="js/index.js"></script>
</body>
</html>
index.js:
DZ.init({
appId: "253122",
channelUrl: "http://mopho.local/deezer-channel.html",
});
document.getElementById("dtest").addEventListener("click", () => {
DZ.login(function(response) {
console.log("1",response);
}, {perms: 'basic_access,email'});
});
document.getElementById("lstat").addEventListener("click", () => {
DZ.getLoginStatus(function(response) {
console.log(response);
});
});
document.getElementById("getme").addEventListener("click", () => {
DZ.api('/user/me',
function(response) {
console.log("2",response);
}
);
});
deezer-channel.html:
<script src="http://cdn-files.deezer.com/js/min/dz.js"></script>
mopho.local在我的hosts文件中配置+nginx指向127.0.0.1。
我的 Deezer 应用具有以下配置:
Application domain: mopho.local
Redirect URL after authentication: http://mopho.local
【问题讨论】: