Soundcloud API 错误 NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝 (JavaScript) [英] Soundcloud API Error NS_ERROR_DOM_BAD_URI: Access to restricted URI denied (JavaScript)

查看:39
本文介绍了Soundcloud API 错误 NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝 (JavaScript)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚熟悉了 Soundcloud 的 API,但遇到了一些麻烦.据我所知,在 SC.initialize 中我需要的只是一个 client_id.我已经使用 Code Academy 的教程开始学习,它很棒.现在我实际上是在尝试实现一些东西,但我遇到了一些麻烦.
当我在 Code Academy 运行我的代码时,它完全按照我的意愿运行.现在我正在尝试在浏览器中运行它,但出现空白屏幕和此错误:

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:访问受限 URI 被拒绝@http://connect.soundcloud.com/sdk

NS_ERROR_DOM_BAD_URI: Access to restricted URI denied @ http://connect.soundcloud.com/sdk

经过一些研究,我发现这些错误与域前缀有关.所以我尝试将其更改为 http://www.connect.soundcloud.com/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.com/sdk. But when I do that, I get a different error:

SC 未定义

AHHHH 我做错了什么?!
我是使用 API 的新手,非常感谢您的任何帮助.
这是我正在做的:
(JavaScript)

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.com/sdk.js"></script>
        <script src="soundcloud.js"></script>
    </head>
    <body>
        <div id="tracktitle"></div>
        <div id="trackimage"></div>
        <div id="play"></div>
    </body>
</html>

我真的不认为代码有什么问题,因为在 Code Academy 中一切似乎都运行良好.我认为让自己熟悉 API 更像是一个问题.我需要做一些进一步的身份验证吗?我需要的不仅仅是客户 ID 吗?我再次陷入困境,并希望对此提供任何帮助.感谢阅读.

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.

(我还按照 Coding for GOOD 的 Soundcloud API 集成教程一步一步地进行操作,我得到了完全相同的错误,因此这进一步证实了代码可能不是问题,但连接到 API 可能是)

(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)

推荐答案

这里的问题是,当连接到托管在另一台服务器上的 API 时,您必须使用相同的协议.对于本地文件,您使用文件协议 (file://),其中 soundcloud 使用:http://https://

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

请按照以下步骤操作:

  1. 获取服务器(XAMPP/LAMPP/WAMPP 用于 PHP/常规 HTML,NodeJS 用于 JS 服务器,或 Tornado 用于 Python)
  2. 找到您的服务器使用的协议

如果您的服务器使用 http 协议,那么您的域必须是 http://soundcloud.com/...,但如果您的服务器使用 https 协议,那么 API 的域必须是 https://.....因此,一旦您获得了匹配的协议,您就可以通过 API 传递数据.

If you server uses the http protocol, then your domain must be http://soundcloud.com/..., 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.

这篇关于Soundcloud API 错误 NS_ERROR_DOM_BAD_URI:访问受限 URI 被拒绝 (JavaScript)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆