2016-02-29 108 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註冊以便上傳您的文件。

此錯誤可能還有其他原因,但是對於我的情況而言,情況並非如此,解決了問題。

相關問題