我正在尝试在我的应用中添加一个超级基本的Soundcloud功能,以使用他们的UI上传单个.wav文件。我按照他们的指南,我真的不需要在裸骨共享菜单之外的任何东西,所以我假设这个代码将工作:
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 :(得分:1)
在SoundCloud中获取HTTP 422错误的原因之一是:
如果您是第一次尝试使用新帐户上传文件,则需要验证您的电子邮件地址以完成SoundCloud注册才能上传文件。
这个错误可能还有其他原因,但是对于我的情况来说就是这种情况并且解决了这个问题。
答案 1 :(得分:0)
上传曲目时无法引用外部资源。您 因此需要将轨道下载到您的计算机,然后执行 实际上传到SoundCloud。
答案 2 :(得分: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);
}
}];