I am currently working with the SoundCloud API and want the track to be embedded at the click of a button.
I get two errors:
XMLHttpRequest cannot load http://soundcloud.com/oembed.json?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F48419073 . The origin of null is not allowed through Access-Control-Allow-Origin.
and
Uncaught TypeError: Cannot read property 'html' null
Here is my code:
<button onclick="getPopular()">+1</button>
<div id="track"></div>
<script src="http://connect.soundcloud.com/sdk.js" type="text/JavaScript"></script>
<script type="text/JavaScript">
SC.initialize({
client_id: "**************",
});
var getPopular = function() {
SC.get("/tracks", {limit: 1}, function(tracks) {
var track = tracks[0];
alert("Latest track: " + track.title);
SC.oEmbed(track.uri, document.getElementById("track"));
});
};
</script>
I use a warning in my code to report that it is actually accepting information from the SoundCloud API. I'm just not sure what else impedes its implementation.
Thank you ahead of time, or look at my question.
source
share