soundcloud - Javascript SDK connect() 函数在 chrome 中不起作用

标签 soundcloud

我正在尝试按照此处的示例对我的代码进行建模:http://connect.soundcloud.com/examples/connecting.html#

它在 firefox 中有效,但在 chrome 中无效。在 chrome 中,soundcloud 弹出窗口正确显示,我可以登录(返回 sc-connect.html),但窗口不会关闭。仔细检查后,发现有一个 javascript 错误,因为 window.opener 为空。我想知道这是否与 localhost uri 有关?上面链接中的示例适用于 firefox 和 chrome。有任何想法吗?我的代码如下:

SC.initialize({client_id:'my_client_id', redirect_uri:'http://localhost:3000/sc-connect.html'});

$('button').click(function(){
  SC.connect(function () {
    console.log('made it');
  }
}

我的 sc-connect.html 页面如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html>
    <head>
      <title>Connect with SoundCloud</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </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>

此应用在 soundcloud 上的重定向 URI:http://localhost:3000/sc-connect.html

最佳答案

这实际上是 Chrome 中的一个奇怪错误,它是由从 Chrome 应用商店安装 SoundCloud 应用程序引起的。很奇怪,我知道。

解决方法是不使用 window.opener,而是将 oauth token 推送到 LocalStorage 或 SessionStorage 并让开启器窗口监听 Storage event .

关于soundcloud - Javascript SDK connect() 函数在 chrome 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9613111/

相关文章:

php - 如何使用 Sound Cloud API 通过标签搜索特定用户的轨道?

soundcloud - 获取相关轨道的列表 HTTP API SoundCloud

actionscript-3 - Soundcloud 和 FLASH

javascript - 仅在我的 ubuntu 服务器上从 soundcloud api 收到 500 错误

尽管用户有轨道,SoundCloud API 仍返回 0 首轨道

javascript - 使用 Soundcloud 播放器按钮更改嵌入的页面上的元素

ios - Soundcloud iframe 不适用于 UIWebView swift

javascript - 使用 javascript 将歌曲上传到 Soundcloud 帐户

api - 过滤用户轨道时的 Soundcloud API 错误

codeigniter - 如何使用 Codeigniter 将文件上传到 Soundcloud?