创建新的播放列表的SoundCloud(套)与JS SDK返回422 [英] Creating a new Soundcloud playlist ( set ) with their JS SDK returns 422

查看:232
本文介绍了创建新的播放列表的SoundCloud(套)与JS SDK返回422的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给谁用的SoundCloud连接,以形成对存储的SoundCloud与SC帐户新的播放列表(套)的能力的用户。非常基本的。作为测试情况下,我测试的例子是几乎完全从的SoundCloud开发文档但我添加了一个不同的声音ID。

I am trying to give users who are connected with Soundcloud the ability to create new playlists ( sets ) stored on Soundcloud with their SC account. Very basic. As a test case the example I am testing is almost exactly taken from the Soundcloud dev docs except I have added a different sound id.

<script src="http://connect.soundcloud.com/sdk.js"></script>
<script>
// initialize client with app credentials
SC.initialize({
  client_id: 'MY_CLIENT_ID',
  redirect_uri: 'http://localhost.local/~****/sc/callback.html'
});

// initiate auth popup and create new playlist
SC.connect(function() {
    SC.get('/me', function(me) {
        console.log(me.username);
    });

    var tracks = [12573606].map(function(id) { return { id: id }; });
    SC.post('/playlists', {
        playlist: { title: 'My Playlist', tracks: tracks }
    });
});

从SC.post及其响应的副本如下:

The copy from the SC.post and its response are as follows:

POST https://api.soundcloud.com/playlists 422 (Unknown Error) sdk.js:1
window.SC.SC.Helper.merge._xhrRequest sdk.js:1
window.SC.SC.Helper.merge._request sdk.js:1
window.SC.SC.Helper.merge._apiRequest sdk.js:1
window.SC.SC.Helper.merge.post sdk.js:1

(anonymous function) localhost.local:21
(anonymous function) sdk.js:1
f.onreadystatechange sdk.js:1

XHR finished loading: "https://api.soundcloud.com/playlists". sdk.js:1
window.SC.SC.Helper.merge._xhrRequest sdk.js:1
window.SC.SC.Helper.merge._request sdk.js:1
window.SC.SC.Helper.merge._apiRequest sdk.js:1
window.SC.SC.Helper.merge.post sdk.js:1
(anonymous function) localhost.local:21
(anonymous function) sdk.js:1
f.onreadystatechange sdk.js:1

Uncaught TypeError: object is not a function sdk.js:1
(anonymous function) sdk.js:1
f.onreadystatechange

我已经尝试了几种不同的解决方案,以及创建URL请求自己和与它一起发布CLIENT_ID我但没有成功。

I've tried a couple different solutions as well as creating the url request myself and posting along with it my client_id but haven't had any success.

我注意到在开发文档不一致了。我注意到的是,在开发文档有一个播放列表创建JS SDK例子但是在APIGEE(API)控制台有没有提及一个职位/播放列表的请求,只/播放列表的获取......这难道不是即使在当前的SoundCloud的API比存在?

I've noticed an inconsistency in the dev docs too. I've noticed is that in the dev docs there is a create playlist JS SDK example however in the APIGEE ( API ) Console there isn't reference to a post /playlists request, just /playlists for a get... Does this not even exist in the current Soundcloud api than?

这掠过我脑海的另一件事是,由于这是一个错误422,你可以只曲目添加到播放列表当用户使用SDK最初上传的轨道?

The other thing that crossed my mind was that since it was a 422 error can you only add tracks to playlists when a user is uploading the track originally with the sdk?

有没有其他人碰到这个问题?有没有人找到任何解决方案呢?

Has anyone else run into this issue? Has anyone found any solutions to it?

谢谢,

推荐答案

我使用可可通过/目标C的SoundCloud API,不得不试图更新播放列表时收到错误422的同样的问题。我的解决办法是了解该参数值必须是跟踪ID的字符串数组,该参数关键是播放列表[曲目] [] [ID]。

I am using the SoundCloud API via Cocoa/Objective C and had the same problem of getting Error 422 when trying to update playlists. My solution was in understanding that the parameter value must be an array of track "id" strings, and that the parameter key is "playlist[tracks][][id]".

因此​​,对于目标C,在code是:

So, for Objective C, the code is:

NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
NSString *trackList = @"60832750,61311756,60832782"; // for example
NSArray *tracks = [self.trackList componentsSeparatedByString:@","];
[parameters setObject:tracks forKey:@"playlist[tracks][][id]"];

当然,你的确切code将取决于你所使用的语言。对我来说,关键是掌握其所有括号正确的,关键的。

Of course, your exact code will depend on the language you're using. For me, the trick was getting that key with all its brackets correct.

这篇关于创建新的播放列表的SoundCloud(套)与JS SDK返回422的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆