Soundcloud SDK - 从 url 加载曲目

Soundcloud SDK - load track from url

所以我通过 CodeAcademy here and wanted to take the knowledge I learned from that and put it on Codepen. But I want to use a different track than the one they use in this tutorial - specifically this song https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download 做了一个关于 Soundcloud SDK 的教程。

我读到 /resolve 是获取 trackid 的好方法,但它不起作用。我在控制台中得到 403 Forbidden

SC.get('/resolve/?url=https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download&client_id=3596a42d6242b9c1ee76740a7771d33a', function(track) {
  console.log(track); // returns null
});

这是我的codepen。请帮助我为我的基本 SoundCloud SDK 音频播放器加载此曲目。谢谢

您的代码是正确的,甚至适用于某些曲目,例如文档中的曲目。

你遇到了一个我个人认为应该在他们的文档中强调的问题。此轨道的 API 访问已被禁用(即使启用了小部件),因此您无权使用 API 查询此轨道并且它 returns 403 禁止 HTTP 状态代码。

这在 SoundCloud terms of useLinked Services 部分中有描述:

You can limit and restrict the availability of certain of Your Content to other users of the Platform, and to users of Linked Services, at any time using the permissions tab in the track edit section for each sound you upload, subject to the provisions of the Disclaimer section below.

如果在获取曲目信息时遇到任何此类错误,您可以检查您的代码,并根据成功或失败,继续正确的操作:

var clientId = 'CLIENT_ID';

SC.initialize({
  client_id: clientId
});

var songUrl = 'https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download';

SC.get('/resolve?url=' + songUrl + '&client_id=' + clientId, function(data, error) {
  if (error === null) {
    console.log('Do something like playing the song.');
  } else {
    console.log('Print an error message?');
  }
});