我该怎么做与的SoundCloud的Javascript SDK中的/化解? [英] How can I do a /resolve with the Soundcloud Javascript SDK?
问题描述
我想我的应用程序给用户
- 粘贴在的SoundCloud轨道URL到
<输入>
字段 - preSS一个提交
<按钮和GT;
- 有一个函数返回轨道的
ID
到目前为止,我知道该怎么做一个 /决心
的唯一方法是通过命令行的卷曲
命令证明这里 http://developers.soundcloud.com/docs/api/reference#resolve。有没有办法通过一个Javascript功能来做到这一点?
例如
SC.resolve(trackURL,ID功能(ID,错误){});
所有卷曲
确实是一个HTTP请求。 JavaScript是绝对能够做一个HTTP请求,这样做的最常见的方法是使用<一个href=\"https://developer.mozilla.org/en-US/docs/Web/API/XMLHtt$p$pquest/Using_XMLHtt$p$pquest?redirectlocale=en-US&redirectslug=DOM%2FXMLHtt$p$pquest%2FUsing_XMLHtt$p$pquest\">XMLHtt$p$pquest也称为AJAX。
热门库,如jQuery的简化发出这些请求,例如:
//一个你可以从http://soundcloud.com/you/apps得到更换YOUR_CLIENT_ID
VAR trackUrl ='http://soundcloud.com/matas/hobnotropic';
$获得(
http://api.soundcloud.com/resolve.json?url='+ trackUrl +'和; CLIENT_ID = YOUR_CLIENT_ID',
功能(结果){
的console.log(结果);
}
);
工作例如 href=\"http://jsbin.com/oradug/1/edit\">。
I would like a user of my app to
- paste in a Soundcloud track URL to a
<input>
field - press a submit
<button>
- have a function return the track's
id
So far the only way I know how to do a /resolve
is via command line's curl
command as demonstrated here http://developers.soundcloud.com/docs/api/reference#resolve. Is there a way to do this via a Javascript function?
e.g.
SC.resolve(trackURL, id, function(id, error){});
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.
这篇关于我该怎么做与的SoundCloud的Javascript SDK中的/化解?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!