我試圖下載與Twilio帳戶關聯的所有錄製對象,但在TwilioVoiceClient.h或VoiceClient.h中沒有看到實現此目的的任何方法。我正在使用ProgramableVoice iOS SDK(測試版5),但在線文檔不顯示任何objective-c或Swift。我可以,如果拍攝SID被稱爲像這樣以播放個人記錄,沒有任何問題:使用可編程語音SDK檢索Twilio上的所有錄製文件
NSString *baseString = @"https://api.twilio.com/2010-04-01/Accounts/";
NSString *recordingSID = @"RExxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
NSURL *recordingUrl = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@/Recordings/%@.mp3", baseString, kTwilAccount, recordingSID]];
avPlayer = [[AVPlayer alloc]initWithURL:recordingUrl];
我想什麼做雖然是下載所有相關的記錄對象帳戶。對於這一點,我轉身NSURLConnection的:
NSString *baseStr = [NSString stringWithFormat:@"https://api.twilio.com/2010-04-01/Accounts/%@/Recordings.json", kTwilAccount];
NSURL *url = [NSURL URLWithString:baseStr];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:1000.0];
NSString *authStr = [NSString stringWithFormat:@"%@:%@", kTwilAccount, authToken];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:@"Base %@", [authData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]];
[theRequest setValue:authValue forHTTPHeaderField:@"Authorization"];
[NSURLConnection sendAsynchronousRequest:theRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *responseCode, NSData *responseData, NSError *responseError) {
if ([responseData length] > 0 && responseError == nil){
// do work
} else if ([responseData length] == 0 && responseError == nil){
NSLog(@"data error: %@", responseError);
} else if (responseError != nil && responseError.code == NSURLErrorTimedOut){
NSLog(@"data timeout: %ld", (long)NSURLErrorTimedOut);
} else if (responseError != nil){
NSLog(@"data download error: %@", responseError);
}
}];
這導致下載錯誤與控制檯輸出:
數據下載錯誤:錯誤域= NSURLErrorDomain代碼= -1012 「(空)」 的UserInfo = {NSErrorFailingURLStringKey = https://api.twilio.com/2010-04-01/Accounts/ACdee27262ef5fd27a593a697d80e7f7b0/Recordings.json,NSUnderlyingError = {0x17084aa70誤差區域= kCFErrorDomainCFNetwork代碼= -1012 「(空)」 的UserInfo = {_ kCFURLErrorAuthFailedResponseKey = {URL = https://api.twilio.com/2010-04-01/Accounts/ACdeedkfdjieireijrekjrkejrk4kj4/Recordings.json}}},NSErrorFailingURLKey = https://api.twilio.com/2010-04-01/Accounts/ACdeedkfdjieireijrekjrkejrk4kj4/Recordings.json}
顯然,要麼不識別端點或不識別端點就像我認證的方式一樣。我應該如何在objective-c中請求這些信息?
感謝您的閱讀。