Soundcloud authentication/connection javascript issue

做~自己de王妃 提交于 2019-12-08 13:25:00

问题


<script src="http://connect.soundcloud.com/sdk.js"></script>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'bea6b4a2c1108a4cfa99f0d40966108a',
  redirect_uri: 'http://www.samplewars.com/'
});

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


Unsafe JavaScript attempt to access frame with URL http://samplewars.com/soundcloud/ from frame with URL http://www.samplewars.com/soundcloud/?code=77c9dc160d723a52f67d42a89067848e&state=SoundCloud_Dialog_80886#access_token=1-26934-195352-78151464de9a2ec39&scope=non-expiring. Domains, protocols and ports must match.

I'm getting this error in my chrome console, and in FF it just keeps looping through the allow process without shooting out the alert.

Funny thing is, it worked for a second, then I went to get a drink, came back, and it was broken.

edit: it also stays inside of the popup as opposed to closing back to the original window edit 2: it ALSO actually adds the permissions inside of soundcloud in the connect menu for the app. Just doesn't spit out the alert.

Edit 3: Okay, it works in FF now after I added an onclick event to stop it from constantly looping through the js. so now the code is:

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'bea6b4a2c1108a4cfa99f0d40966108a',
  redirect_uri: 'http://www.samplewars.com/'
});

// initiate auth popup
function connectSC(){
SC.connect(function() {
  SC.get('/me', function(me) { 
    alert('Hello, ' + me.username); 
  });
});
}
</script>
<div id="connect_button" onClick="connectSC()">
connect to soundcloud
</div>

Which works in FF, but not in Chrome or IE.


回答1:


Interesting factor. I found the issue, if you try to connect using an URL without www. as the prefix, it won't work. Soundcloud must require it in order to build the token



来源:https://stackoverflow.com/questions/13310896/soundcloud-authentication-connection-javascript-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!