可以't使用javascript通过soundcloud API向群组添加曲目
Can't add a track to a group via soundcloud API using javascript
我已经从github克隆了javascript SDK,除了Firefox15.0不高兴之外,我还可以获得任何我想要的东西。(曲目列表、分组列表)。
我希望能够将我的一首曲目添加到我的一个组中(到目前为止,为了保持测试的简单性,我每个组只有一首。)控制台允许我添加(PUThttps://api.soundcloud.com/groups/92779/contributions/58889291)并从组中删除相同的轨道(使用相同URI的DELETE),但我不使用JavaScriptSDKjQuery示例。(我开始认为是jquery.sc.api.js,但我不确定我是在寻求帮助。)
到目前为止,这就是我所破解的:(好吧,我做了很多,但我已经把它删掉了,只突出了这个例子。)
index.html
<!DOCTYPE html>
<html>
<head><meta charset="utf-8" />
<title>SC.js.test</title>
<script> var FireFox15_error = 'Error: ReferenceError: id is not defined '
Source File: jquery.tmpl.js Line: 126'
</script>
<style type="text/css">.hidden { visibility: hidden; }</style>
</head>
<body>
<div id="container">
</div>
<div id="tracks" class="hidden">
<h2>Your tracks</h2>
<ul id="track-list">
</ul>
The Add button seems 'to work' if the track is already in the group, but just redirects to the login page if it isn't (is this a sign that the token isn't being sent with the PUT ?)
</div>
<!-- am I'm just old wanting to move these into the <head> ? -->
<script type="text/javascript" charset="utf-8" src="jquery_1.7.1_min.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.tmpl.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.sc.api.js"></script>
<script type="text/javascript" charset="utf-8" src="main.js"></script>
<!-- Templates -->
<script id="track" type="text/html">
<li data-track-id="${id}" id="${id}">${$i}) <a href="${permalink_url}">${title}</a>(${id})</li>
</script>
<div id="debug" class="hidden">
<h3>Requests/Questions</h3>
<ol>
<li>api.put('/me', { "description": 'Guess who is using the new API function?' }); //please add this</li>
<li> why does sc have a different string than the track_id for removing tracks from a group? </li>
</ol>
</div>
</body></html>
main.js
(function($) {
var soundCloudApiKey = 'should_be_able_to_create_a_key_for_(locked_to)_each_user';
var user_id = '';
var api = $.sc.api(soundCloudApiKey, {
onAuthSuccess: function(user, container) {
user_id = user.id;
$('<span class="username">Logged in as: <strong>' + user.username + '</strong> (' + user_id + ')</a>').prependTo(container);
}
});
$(document).bind($.sc.api.events.AuthSuccess, function(event) {
$(this).click(function(data) {
data.preventDefault();
var Sender = window.event.srcElement;
if(Sender.id == 'add_track_submit'){
var group_id = $('#group_id').val();
var track_id = $('#track_id').val();
alert('TRYING to add track ' + track_id + ' to group ' + group_id);
//api.put('/groups/' + group_id + '/contributions/' + track_id); // http://developers.soundcloud.com/docs/api/guide#contributing-group
api.put('/groups/' + group_id + '/contributions/' + track_id, function(reply, e){ //trying to get some feedback on why this does not work
// It seems to be using a GET rather than a PUT or POST
//api.post('/groups/' + group_id + '/contributions/' + track_id, function(reply, e){ //also does not seem to work
if(e){ console.log('err:' + e); }
console.log('track add reply' + reply);
alert('track ' + track_id + ' added to group ' + group_id);
});
}
return false;
});
api.get('/me/tracks', function(data) {
// you can use new jQuery templating for generating the track list
$('#track').render(data).appendTo("#track-list");
//groovy, if Firefox15.0 did not hate it, (works in Google Chrome 18.0.1025.162/JavaScript V8 3.8.9.18)
$.map( data, function(track, i){
my_group_id = 92779; //dirty hack while I try to get this working with just one track and one group
var add_button = '<span id="add_button"><form id="add_track"><input id="group_id" type="hidden" name="group_id" value="' + my_group_id + '" /> '
<input type="hidden" id="track_id" name="track_id" value="' + track.id + '" /> '
<input type="submit" id="add_track_submit" name="add" value="Add ' + track.title + ' to group ' + my_group_id + '" /></form></span>';
$('#track-list>#' + track.id).append(add_button);
});
$('div').removeAttr("class", "hidden");
});
});
})(jQuery);
在SDK中发现错误并修复:https://github.com/alexxroche/SoundCloud-API-jQuery-plugin/blob/master/jquery.sc.api.js-我的代码不需要更改。
相关文章:
- 如何更改bigquery API中的计费层选项
- Amazon S3 REST API大小不正确
- 客户端服务器REST API captcha实现
- 使用Facebook live API创建实时视频对象时的隐私设置
- 可以't使用javascript通过soundcloud API向群组添加曲目
- Last.fm API发送2个曲目时,我要求一个,如果我正在听一首歌
- 使用javascript API响应内部服务器错误将曲目上传到SoundCloud
- 获取 Spotify 用户 [Web API] 当前播放的曲目名称
- Soundcloud API - 使用 SC.recordupload 从外部 URL 上传曲目图稿的图像
- Metro JS API-获取当前媒体播放器曲目
- 使用Spotify API插件专辑名称和歌手名称搜索曲目
- Spotify API-从临时播放列表中删除所有曲目
- Spotify API-获取播放列表中每个曲目的曲目URI
- SoundCloud API搜索带有标签过滤器的曲目
- 通过Spotify App API从队列中获取下一首曲目
- 使用Spotify Web API播放曲目
- Spotify预览API搜索曲目和专辑
- 如何通过SoundCloud API切换播放和暂停曲目
- soundcloud API -检测曲目是否不存在
- 使用Meteor Spotify API根据单词搜索返回专辑列表,并需要为列表中的每个专辑拉入曲目