2017-01-20 17 views
0

我试图下载与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中请求这些信息?

感谢您的阅读。

回答

1

Twilio开发人员在这里传播。

我们实际上不建议您将您的帐户凭据放入应用程序中,并从您的应用程序进行API调用。恶意攻击者可能会反编译您的应用程序,检索您的凭据并滥用您的帐户。

我们建议您改用服务器端解决方案来调用API并检索您的录制文件。然后,您可以从应用程序与您的服务器通信。

Here's a blog post that explains more and includes an example for sending an SMS from an iOS application.