Soundcloud将歌曲添加到播放列表(ios)

时间:2014-10-11 09:58:34

标签: ios soundcloud

这个问题有一天困扰我,在soundcoud上没有任何关联的Cocoa代码示例。感到失败,我希望得到你的帮助

1 个答案:

答案 0 :(得分:0)

我在这里使用了AFNetworking和这个示例来实现一切:https://github.com/soundcloud/soundcloud-ruby

[parameters setObject:@"YOUR TOKEN" forKey:@"oauth_token"];
[[AFNetworkingClient sharedClient] GET:[NSString stringWithFormat:@"me/playlists/%@.json",@"Some ID"] parameters:parameters


     success: ^(NSURLSessionDataTask *task, id responseObject)
     {

         NSMutableArray * ids = [[NSMutableArray alloc]init];
         for (id trackDictionary in [responseObject objectForKey:@"tracks"]) {
             Track * track = [[Track alloc]initWithDictionary:trackDictionary error:nil];
             [ids addObject:track.id];
         } // Get all IDS

         [ids addObject:@"NEW ID"]; // Add the new ID to the array

         NSMutableArray * idArray = [[NSMutableArray alloc]init];
         for (NSNumber *idNumber in ids) {
             [idArray addObject:@{@"id":idNumber}]; // Create an Array of Dictionarys
         } //[{@"id":23232},{@"id":345454}]


         NSMutableDictionary * parameters = [[NSMutableDictionary alloc]init];
         [parameters setObject:@"YOUR TOKEN"];
         [parameters setObject:@{@"tracks":idArray} forKey:@"playlist"];
         [[AFNetworkingClient sharedClient] PUT:[NSString stringWithFormat:@"me/playlists/%@.json",playlist.id] parameters:parameters


            success: ^(NSURLSessionDataTask *task, id responseObject)
          {
          }

           failure: ^(NSURLSessionDataTask *task, NSError *error)
          {
          }];



     }

     failure: ^(NSURLSessionDataTask *task, NSError *error)
     {         
     }];