I am just getting myself acquainted with Soundcloud's API and I am having some trouble. As far as I can tell, all I need in SC.initialize
is a client_id. I have used the tutorials at Code Academy to get started and it was great. Now that I am actually trying to implement something I am running into some trouble.
When I ran my code in Code Academy, it did exactly what I wanted it to do. Now that I am trying to run it in a browser, I am getting a blank screen and this error:
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied @
After doing some research, I have found that those errors are related to domain prefixes. So I tried changing it to http://www.connect.soundcloud/sdk. But when I do that, I get a different error:
SC
is not defined
AHHHH What am I doing wrong?!
I am new to using API's, and any help at all would be very greatly appreciated.
Here is what I am doing:
(JavaScript)
SC.initialize({
client_id: 'hidden for privacy',
});
$(document).ready(function() {
SC.get('/users/5577686/tracks', {limit:7}, function(tracks) {
$(tracks).each(function(index, track) {
$('#tracktitle').append($('<li></li>').html(track.title));
$('#trackimage').append("<img src='" + track.artwork_url + "' />");
$('#play').append("<a href='" + track.permalink_url + "' >" + "Play" + "</a>");
});
});
});
(HTML)
<!DOCTYPE HTML>
<html>
<head>
<script src=".js"></script>
<script src="soundcloud.js"></script>
</head>
<body>
<div id="tracktitle"></div>
<div id="trackimage"></div>
<div id="play"></div>
</body>
</html>
I don't really think there is anything wrong with the code, as everything seemed to be working fine in Code Academy. I think it is more of an issue with familiarizing myself with the API. Do I need to do some further authentication? Do I need something more than just the client ID? Again I am very stuck and would appreciate any amount of help on this. Thanks for reading.
(I also followed along with Coding for GOOD's Soundcloud API Integration tutorial step-by-step and I am getting the same exact errors, so this further confirms that the code is probably not the problem, but connecting to the API may be)
I am just getting myself acquainted with Soundcloud's API and I am having some trouble. As far as I can tell, all I need in SC.initialize
is a client_id. I have used the tutorials at Code Academy to get started and it was great. Now that I am actually trying to implement something I am running into some trouble.
When I ran my code in Code Academy, it did exactly what I wanted it to do. Now that I am trying to run it in a browser, I am getting a blank screen and this error:
NS_ERROR_DOM_BAD_URI: Access to restricted URI denied @
http://connect.soundcloud./sdk
After doing some research, I have found that those errors are related to domain prefixes. So I tried changing it to http://www.connect.soundcloud./sdk. But when I do that, I get a different error:
SC
is not defined
AHHHH What am I doing wrong?!
I am new to using API's, and any help at all would be very greatly appreciated.
Here is what I am doing:
(JavaScript)
SC.initialize({
client_id: 'hidden for privacy',
});
$(document).ready(function() {
SC.get('/users/5577686/tracks', {limit:7}, function(tracks) {
$(tracks).each(function(index, track) {
$('#tracktitle').append($('<li></li>').html(track.title));
$('#trackimage').append("<img src='" + track.artwork_url + "' />");
$('#play').append("<a href='" + track.permalink_url + "' >" + "Play" + "</a>");
});
});
});
(HTML)
<!DOCTYPE HTML>
<html>
<head>
<script src="http://connect.soundcloud./sdk.js"></script>
<script src="soundcloud.js"></script>
</head>
<body>
<div id="tracktitle"></div>
<div id="trackimage"></div>
<div id="play"></div>
</body>
</html>
I don't really think there is anything wrong with the code, as everything seemed to be working fine in Code Academy. I think it is more of an issue with familiarizing myself with the API. Do I need to do some further authentication? Do I need something more than just the client ID? Again I am very stuck and would appreciate any amount of help on this. Thanks for reading.
(I also followed along with Coding for GOOD's Soundcloud API Integration tutorial step-by-step and I am getting the same exact errors, so this further confirms that the code is probably not the problem, but connecting to the API may be)
Share Improve this question edited May 13, 2015 at 5:50 EternalHour 8,6816 gold badges39 silver badges58 bronze badges asked Dec 5, 2013 at 6:41 N1G3LN1G3L 2673 silver badges11 bronze badges 3- 4 SOLVED! In case anyone else runs into this problem: Wasn't aware that the files needed to be hosted on a public server. When I was watching the Coding for GOOD tutorials, he was somehow running them locally. Doh! – N1G3L Commented Dec 5, 2013 at 8:06
- 5 The server doesn't have to be public for that. It just requires running it from a web server, not the file system. There's a lot of different solutions for that, but if you have a Mac you could look at a tool like Anvil. – Marco Commented Dec 6, 2013 at 10:22
- 5 @N1G3L you should add that as an answer to this question and accept it. – Blaise Commented May 31, 2015 at 13:17
1 Answer
Reset to default 1The problem here is that when connecting to an API which is being hosted on another server, you must be using the same protocol. For local files, you use the file protocol (file://
), wheres soundcloud uses: http://
or https://
Follow these steps:
- Get a server (XAMPP/LAMPP/WAMPP for PHP/Regular HTML, NodeJS for JS server, or Tornado for Python)
- Find the protocol which your server uses
If you server uses the http
protocol, then your domain must be http://soundcloud./...
, but if your server uses the https
protocol, then the domain for the API must be https://....
. So once you get the protocols to match, then you will be able to pass data through the API.