gpt4 book ai didi

javascript - Soundcloud JS API 连接方法不起作用

转载 作者:行者123 更新时间:2023-11-29 18:06:28 28 4
gpt4 key购买 nike

我正在尝试使客户端应用程序根据 docs 从 soundcloud 获取轨道我添加了 <script src='http://connect.soundcloud.com/sdk.js'></script><head>我的网站。并按照文档对我的 js 添加了以下代码。

//I've replaced YOUR_CLIENT_ID with my client id I got when registered my app and http://example.com/callback with my callback.html also I've filled redirect uri field with it.
SC.initialize({
client_id: 'YOUR_CLIENT_ID',
redirect_uri: 'http://example.com/callback'
});

// initiate auth popup
SC.connect(function() {
SC.get('/me', function(me) {
alert('Hello, ' + me.username);
});
});

我还创建了 callback.html

<html lang="en">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Connect with SoundCloud</title>
</head>
<body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">
<b style="width: 100%; text-align: center;">This popup should automatically close in a few seconds</b>
</body>
</html>

现在我得到弹出窗口,我可以在其中输入我的电子邮件和密码,当我输入时,我收到消息:此弹出窗口应在几秒钟后自动关闭。但它没有关闭。在控制台中我收到消息:

Uncaught SecurityError: Blocked a frame with origin "http://sscopin.temp.swtest.ru" from accessing a frame with origin "swappedout://".  The frame requesting access has a protocol of "http", the frame being accessed has a protocol of "swappedout". Protocols must match

我也没有看到任何警报,所以我想它没有连接。另外 console.log SC 向我展示了 SC 对象。解决方案?有什么建议吗?

最佳答案

在 Soundcloud 的示例 callback.html 中,代码:

<body onload="window.opener.setTimeout(window.opener.SC.connectCallback, 1)">

必须修改为:

<body onload="window.setTimeout(window.opener.SC.connectCallback, 1)">

如果应用程序设置正确配置到同一域(本地主机或生产,但不是两者的混合),这允许弹出窗口正确关闭并完成登录流程。

关于javascript - Soundcloud JS API 连接方法不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30787900/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com