2016-02-29 64 views
1

我试图在应用程序中使用超级基本Soundcloud功能来使用其UI上传单个.wav文件。我跟着他们的向导,我并没有真的需要裸露的骨头份额菜单以外的任何东西,所以我认为这个代码将工作:SoundCloud API iOS无法上传带有HTTP 422错误的音频

   NSURL *trackURL = [[NSURL alloc] initWithString:[docsDir stringByAppendingPathComponent:fileToShare]]; 

      SCShareViewController *shareViewController; 
      shareViewController = [SCShareViewController shareViewControllerWithFileURL:trackURL 
                     completionHandler:^(NSDictionary *trackInfo, NSError *error){ 

                      if (SC_CANCELED(error)) { 
                       NSLog(@"Canceled!"); 
                      } else if (error) { 
                       NSLog(@"Ooops, something went wrong: %@", [error localizedDescription 
                                 ]); 
                      } else { 
                       // If you want to do something with the uploaded 
                       // track this is the right place for that. 
                       NSLog(@"Uploaded track: %@", trackInfo); 
                      } 
                     }]; 

      // If your app is a registered foursquare app, you can set the client id and secret. 
      // The user will then see a place picker where a location can be selected. 
      // If you don't set them, the user sees a plain plain text filed for the place. 
      [shareViewController setFoursquareClientID:@"<foursquare client id>" 
              clientSecret:@"<foursquare client secret>"]; 

      // We can preset the title ... 
      [shareViewController setTitle:@"Funny sounds"]; 


      // ... and other options like the private flag. 
      [shareViewController setPrivate:NO]; 

      // Now present the share view controller. 
      [self presentModalViewController:shareViewController animated:YES]; 

      [trackURL release]; 

不过,我得到一个HTTP 422错误这个出现在我的调试控制台:

2016-02-29 11:04:47.129 synthQ[801:443840] parameters: { 
    "track[asset_data]" = "/var/mobile/Containers/Data/Application/EE58E5CA-B30C-44EB-B207-EB3368263319/Documents/bb.wav"; 
    "track[downloadable]" = 1; 
    "track[post_to][]" = ""; 
    "track[sharing]" = public; 
    "track[tag_list]" = "\"soundcloud:source=synthQ\""; 
    "track[title]" = "Funny sounds"; 
    "track[track_type]" = recording; 
} 
2016-02-29 11:04:47.164 synthQ[801:444011] -[NXOAuth2PostBodyStream open] Stream has been reopened after close 
2016-02-29 11:04:47.373 synthQ[801:443840] Upload failed with error: HTTP Error: 422 Error Domain=NXOAuth2HTTPErrorDomain Code=422 "HTTP Error: 422" UserInfo={NSLocalizedDescription=HTTP Error: 422} 

有没有人有任何想法这里可能会出错?

谢谢!

回答

0

上传曲目时无法引用外部资源。因此您需要将曲目下载到您的计算机,然后执行 实际上传到SoundCloud。

来源 Soundcloud file uploading issue HTTP 442

+1

这是否意味着我错误地引用了该文件?这些文件位于应用程序的“文档”文件夹中(例如“track [asset_data]”=“/var/mobile/Containers/Data/Application/EE58E5CA-B30C-44EB-B207-EB3368263319/Documents/bb.wav”; is什么是作为轨道文件发送)。所以我不确定我做错了什么? – chmod

0

我设法通过使用经过音频文件作为NSData对象不同的构造函数来解决这个问题:

shareViewController = [SCShareViewController shareViewControllerWithFileData:[NSData dataWithContentsOfFile:[docsDir stringByAppendingPathComponent:fileToShare]] 
                      completionHandler:^(NSDictionary *trackInfo, NSError *error){ 

                       if (SC_CANCELED(error)) { 
                        NSLog(@"Canceled!"); 
                       } else if (error) { 
                        NSLog(@"Ooops, something went wrong: %@", [error localizedDescription 
                                  ]); 
                       } else { 
                        // If you want to do something with the uploaded 
                        // track this is the right place for that. 
                        NSLog(@"Uploaded track: %@", trackInfo); 
                       } 
                      }]; 
1

其中一个原因,去HTTP 422错误SoundCloud是:

如果您尝试首次使用新帐户上传文件,则需要验证电子邮件地址才能完成SoundClou d注册以便上传您的文件。

此错误可能还有其他原因,但是对于我的情况而言,情况并非如此,解决了问题。

相关问题