Javascript SDK connect() function not working in chrome

本小妞迷上赌 提交于 2019-11-30 15:52:55

This is actually a strange bug in Chrome which is caused by installing the SoundCloud app from the Chrome App Store. Bizarre, I know.

A workaround is instead of using window.opener, push the oauth token into LocalStorage or SessionStorage and have the opener window listen to the Storage event.

It looks like you're missing a couple of closing brackets in your example code. Other than that, nothing appears obviously wrong with your example. I copied and pasted your sc-connect.html and used it with the following:

<html>
<head>
  <title>Demo</title>
  <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  <script type="text/javascript" src="http://connect.soundcloud.com/sdk.js"></script>
  <script type="text/javascript">

  $(document).ready(function() {
      SC.initialize({
          client_id: 'MY_CLIENT_ID',
          redirect_uri: 'http://localhost:8080/connect/sc-callback.html'
      });

      $('button').click(function(){
          SC.connect(function() {
              SC.get('/me', function(data) {
                  $('#name').text(data.username);
              });
          });
      });
  });

  </script>
</head>
<body>
  <button>Connect</button>
  <p>
    Hello There, <span id="name"></span>
  </p>
</body>
</html>

This works for me in Firefox and Chrome. Let me know if the that helps.

    <!DOCTYPE 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="text-align: center;">This popup should automatically close in a few seconds</b>
    <script type="text/javascript">window.opener.SC.connectCallback.call(this); </script> 
</body> 
</html> 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!