ERR_FILE_NOT_FOUND observed when SC.oEmbed is Called

余生颓废 提交于 2019-12-12 00:35:11

问题


I wonder to use SC.oEmbed to play sound from SoundCloud.But when I use it, I always get ERR_FILE_NOT_FOUND error.

I put my Source Code in Jsfiddle: http://jsfiddle.net/n2sVk/, it works OK. But when I save it to a HTML file and open it with Chrome, the error would be observed. The Source Code is shown as below:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset="UTF-8">
</head>
<body>

    <script src="http://connect.soundcloud.com/sdk.js"></script>

    <div id="wrap"></div>
    <script type="text/javascript">
        SC.initialize({
            client_id: "c202b469a633a7a5b15c9e10b5272b78",
            redirect_uri: "http://connect.soundcloud.com/examples/callback.html"
        });

        SC.connect(function(){
            console.log("connect " + "return"); 
            SC.get("/me", function(me){
            console.log("me.username:" + me.username);
            console.log("me.description:" + me.description);

            SC.get("/tracks", {limit: 1}, function(tracks){
                console.log("get track return");
                track = tracks[0];
                console.log("track.uri: " + track.uri);
                console.log("track.title: " + track.title);
                SC.oEmbed(track.permalink_url, 
                          {auto_play: true},
                          document.getElementById("wrap"));        
                });
            });
        });
    </script>

</body>

Here is the error from Chrome:

GET file://soundcloud.com/oembed.json?auto_play=true&url=http%3A%2F%2Fsoundcloud.com%2Fyung-crusty-beats%2Fmystic-juice net::ERR_FILE_NOT_FOUND sdk.js:1 oEmbed response: null


回答1:


This happens because when you are testing it locally, you are on "file:///" protocol.

The library's source code is using // in place of the protocol – this lets the library work on both http and https. However, when you access your code from a file as opposed to a webserver, the oembed function will probably not work.

The solution will be to run a local web server, such as Python simple server, which you'd run from the root folder of your project:

python -m SimpleHTTPServer


来源:https://stackoverflow.com/questions/24028678/err-file-not-found-observed-when-sc-oembed-is-called

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