Soundcloud API Error NS_ERROR_DOM_BAD_URI: Access to restricted URI denied (JavaScript) - Stack Overflow

I am just getting myself acquainted with Soundcloud's API and I am having some trouble. As far as

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
Add a ment  | 

1 Answer 1

Reset to default 1

The 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:

  1. Get a server (XAMPP/LAMPP/WAMPP for PHP/Regular HTML, NodeJS for JS server, or Tornado for Python)
  2. 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742416734a4439884.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信