How can I do a /resolve with the Soundcloud Javascript SDK?

ぐ巨炮叔叔 提交于 2019-12-03 21:51:23

All curl does is an HTTP request. JavaScript is definitely able to do an HTTP request, most common way of doing that is by using XMLHttpRequest also known as AJAX.

Popular libraries, such as jQuery simplify issuing these requests, for example:

// replace YOUR_CLIENT_ID with one you can get from http://soundcloud.com/you/apps
var trackUrl = 'http://soundcloud.com/matas/hobnotropic';
$.get(
  'http://api.soundcloud.com/resolve.json?url=' + trackUrl + '&client_id=YOUR_CLIENT_ID', 
  function (result) {
    console.log(result);
  }
);

Working example here.

You can actually use SC.get() directly for almost every resources in the API (without jQuery). Like this:

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

<script>

   SC.initialize({
       client_id: "YOUR_CLIENT_ID"
   });

   SC.get("/resolve/?url=https://soundcloud.com/dogwill", {limit: 1}, function(result){
       console.log(result);
   });

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