使用javascript API响应内部服务器错误将曲目上传到SoundCloud

Upload track to SoundCloud with javascript API respond Internal Server Error

本文关键字:曲目 SoundCloud 错误 API javascript 响应 内部 服务器 使用      更新时间:2023-09-26

我正在尝试通过JAVASCRIPT API将曲目上传到SoundCloud,代码为:

<!DOCTYPE html>
<html>
<head>
  <title>Upload track</title>
  <script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
  <script>
    var blob = "MY_BLOB";
    SC.initialize({
      client_id: 'MY_CLIENT_ID',
      oauth_token: 'MY_TOKEN',
      refresh_token: 'MY_REFRESH_TOKEN'
    });
    var upload = SC.upload({
      file: blob, // a Blob of your WAV, MP3...
      title: 'HTML test',
      genre: 'Electronic',
      description: 'This is a good! track'
    });
  </script>
</head>
<body>
</body>
</html>

我从以前的请求中获得oauth_tokenrefresh_token。我得到的回复是:

{"errors":[{"error_message":"500 - Internal Server Error"}]}

我认为我的blob是不正确的,但如果我把它放在音频标签中:

<audio controls>
  <source src="MY_BLOB" type="audio/ogg">
</audio>

它是有效的。也就是说blob不是问题所在。问题出在哪里?

您应该按照进行尝试

<script src="https://connect.soundcloud.com/sdk/sdk-3.0.0.js"></script>
<script>
// When you have recorded a song with the SDK or any Web Audio application,
// you can upload it if it's in a format that is accepted
SC.upload({
  file: theBlob, // a Blob of your WAV, MP3...
  title: 'This is my sound'
});
</script>

来源=https://developers.soundcloud.com/docs/api/guide#uploading