2017-01-20 16 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.