sc api test
This commit is contained in:
+107
-35
@@ -52,9 +52,11 @@
|
|||||||
secureDocument = (document.location.protocol === 'https:'),
|
secureDocument = (document.location.protocol === 'https:'),
|
||||||
// convert a SoundCloud resource URL to an API URL
|
// convert a SoundCloud resource URL to an API URL
|
||||||
scApiUrl = function(url, apiKey) {
|
scApiUrl = function(url, apiKey) {
|
||||||
|
// var resolver = ( secureDocument || (/^https/i).test(url) ? 'https' : 'http') + '://api.' + domain + '/resolve?url=',
|
||||||
|
// params = 'format=json&consumer_key=' + apiKey +'&callback=?';
|
||||||
var resolver = ( secureDocument || (/^https/i).test(url) ? 'https' : 'http') + '://api.' + domain + '/resolve?url=',
|
var resolver = ( secureDocument || (/^https/i).test(url) ? 'https' : 'http') + '://api.' + domain + '/resolve?url=',
|
||||||
params = 'format=json&consumer_key=' + apiKey +'&callback=?';
|
params = 'format=json&callback=?';
|
||||||
|
// debugger;
|
||||||
// force the secure url in the secure environment
|
// force the secure url in the secure environment
|
||||||
if( secureDocument ) {
|
if( secureDocument ) {
|
||||||
url = url.replace(/^http:/, 'https:');
|
url = url.replace(/^http:/, 'https:');
|
||||||
@@ -258,40 +260,110 @@
|
|||||||
playerObj = {node: $player, tracks: []},
|
playerObj = {node: $player, tracks: []},
|
||||||
loadUrl = function(link) {
|
loadUrl = function(link) {
|
||||||
var apiUrl = scApiUrl(link.url, apiKey);
|
var apiUrl = scApiUrl(link.url, apiKey);
|
||||||
$.getJSON(apiUrl, function(data) {
|
// $.getJSON(apiUrl, function(data) {
|
||||||
// log('data loaded', link.url, data);
|
// // log('data loaded', link.url, data);
|
||||||
index += 1;
|
// index += 1;
|
||||||
// added by Bach for MJ
|
// // added by Bach for MJ
|
||||||
data.href = link.href;
|
// data.href = link.href;
|
||||||
if(data.tracks){
|
// if(data.tracks){
|
||||||
// log('data.tracks', data.tracks);
|
// // log('data.tracks', data.tracks);
|
||||||
playerObj.tracks = playerObj.tracks.concat(data.tracks);
|
// playerObj.tracks = playerObj.tracks.concat(data.tracks);
|
||||||
}else if(data.duration){
|
// }else if(data.duration){
|
||||||
// a secret link fix, till the SC API returns permalink with secret on secret response
|
// // a secret link fix, till the SC API returns permalink with secret on secret response
|
||||||
data.permalink_url = link.url;
|
// data.permalink_url = link.url;
|
||||||
// if track, add to player
|
// // if track, add to player
|
||||||
playerObj.tracks.push(data);
|
// playerObj.tracks.push(data);
|
||||||
}else if(data.creator){
|
// }else if(data.creator){
|
||||||
// it's a group!
|
// // it's a group!
|
||||||
links.push({url:data.uri + '/tracks'});
|
// links.push({url:data.uri + '/tracks'});
|
||||||
}else if(data.username){
|
// }else if(data.username){
|
||||||
// if user, get his tracks or favorites
|
// // if user, get his tracks or favorites
|
||||||
if(/favorites/.test(link.url)){
|
// if(/favorites/.test(link.url)){
|
||||||
links.push({url:data.uri + '/favorites'});
|
// links.push({url:data.uri + '/favorites'});
|
||||||
}else{
|
// }else{
|
||||||
links.push({url:data.uri + '/tracks'});
|
// links.push({url:data.uri + '/tracks'});
|
||||||
}
|
// }
|
||||||
}else if($.isArray(data)){
|
// }else if($.isArray(data)){
|
||||||
playerObj.tracks = playerObj.tracks.concat(data);
|
// playerObj.tracks = playerObj.tracks.concat(data);
|
||||||
|
// }
|
||||||
|
// if(links[index]){
|
||||||
|
// // if there are more track to load, get them from the api
|
||||||
|
// loadUrl(links[index]);
|
||||||
|
// }else{
|
||||||
|
// // if loading finishes, anounce it to the GUI
|
||||||
|
// playerObj.node.trigger({type:'onTrackDataLoaded', playerObj: playerObj, url: apiUrl});
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// https://developers.soundcloud.com/docs/api/guide#authentication
|
||||||
|
// # obtain the access token
|
||||||
|
// $ curl -X POST "https://api.soundcloud.com/oauth2/token" \
|
||||||
|
// -H "accept: application/json; charset=utf-8" \
|
||||||
|
// -H "Content-Type: application/x-www-form-urlencoded" \
|
||||||
|
// --data-urlencode "grant_type=client_credentials" \
|
||||||
|
// --data-urlencode "client_id=YOUR_CLIENT_ID" \
|
||||||
|
// --data-urlencode "client_secret=YOUR_CLIENT_SECRET"
|
||||||
|
$.ajax({
|
||||||
|
method: 'POST',
|
||||||
|
url: 'https://api.soundcloud.com/oauth2/token',
|
||||||
|
data: {
|
||||||
|
'grant_type' : "client_credentials",
|
||||||
|
'client_id' : "965bd4363fdd909723749b003be67125",
|
||||||
|
'client_secret': "bb68647335a47f104a86dcddf4e70fa8"
|
||||||
|
},
|
||||||
|
headers: {
|
||||||
|
"accept" : "application/json; charset=utf-8",
|
||||||
|
"Content-Type" : "application/x-www-form-urlencoded",
|
||||||
|
"Authorization": "OAuth 965bd4363fdd909723749b003be67125"
|
||||||
}
|
}
|
||||||
if(links[index]){
|
});
|
||||||
// if there are more track to load, get them from the api
|
|
||||||
loadUrl(links[index]);
|
// $.ajax({
|
||||||
}else{
|
// "dataType": "json",
|
||||||
// if loading finishes, anounce it to the GUI
|
// "url": apiUrl,
|
||||||
playerObj.node.trigger({type:'onTrackDataLoaded', playerObj: playerObj, url: apiUrl});
|
// "data": {},
|
||||||
}
|
// "headers": {
|
||||||
});
|
// "Authorization": "OAuth " + apiKey
|
||||||
|
// },
|
||||||
|
// "success": function(data) {
|
||||||
|
// // log('data loaded', link.url, data);
|
||||||
|
// index += 1;
|
||||||
|
// // added by Bach for MJ
|
||||||
|
// data.href = link.href;
|
||||||
|
// if(data.tracks){
|
||||||
|
// // log('data.tracks', data.tracks);
|
||||||
|
// playerObj.tracks = playerObj.tracks.concat(data.tracks);
|
||||||
|
// }else if(data.duration){
|
||||||
|
// // a secret link fix, till the SC API returns permalink with secret on secret response
|
||||||
|
// data.permalink_url = link.url;
|
||||||
|
// // if track, add to player
|
||||||
|
// playerObj.tracks.push(data);
|
||||||
|
// }else if(data.creator){
|
||||||
|
// // it's a group!
|
||||||
|
// links.push({url:data.uri + '/tracks'});
|
||||||
|
// }else if(data.username){
|
||||||
|
// // if user, get his tracks or favorites
|
||||||
|
// if(/favorites/.test(link.url)){
|
||||||
|
// links.push({url:data.uri + '/favorites'});
|
||||||
|
// }else{
|
||||||
|
// links.push({url:data.uri + '/tracks'});
|
||||||
|
// }
|
||||||
|
// }else if($.isArray(data)){
|
||||||
|
// playerObj.tracks = playerObj.tracks.concat(data);
|
||||||
|
// }
|
||||||
|
// if(links[index]){
|
||||||
|
// // if there are more track to load, get them from the api
|
||||||
|
// loadUrl(links[index]);
|
||||||
|
// }else{
|
||||||
|
// // if loading finishes, anounce it to the GUI
|
||||||
|
// playerObj.node.trigger({type:'onTrackDataLoaded', playerObj: playerObj, url: apiUrl});
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
// "error": function(errorThrown) {
|
||||||
|
// console.error(JSON.stringify(errorThrown.error()));
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
};
|
};
|
||||||
// update current API key
|
// update current API key
|
||||||
apiKey = key;
|
apiKey = key;
|
||||||
|
|||||||
Reference in New Issue
Block a user