如何下载音频文件?

问题描述:

我想用Google Drive API下载音频文件(mp3,m4a,wma ...)。尝试下面的代码,我得到了模拟器上的错误。如何下载音频文件?

错误:

The operation could't be completed. (The user has not granted the app xxxx read access to the file alEnlflseiFNSEi.) 

代码:

let url = "https://www.googleapis.com/drive/v3/files/\(identifier)?alt=media" 

service.fetchObject(
    with: URL(string: url)!, 
    delegate: self, 
    didFinish: #selector(GoogleDriveFileListTableViewController.downloadWithTicket(ticket:finishedWithObject:error:)) 
) 

// Parse results and display 
func downloadWithTicket(ticket : GTLServiceTicket, finishedWithObject response : GTLDriveFileList, error : NSError?) { 
    if let error = error { 
     showAlert(title: "Error", message: error.localizedDescription) 
     return 
    } 

} 

关于这里你 “读访问” 的问题是什么Download files states

Downloading the file requires the user to have at least read access. Additionally, your app must be authorized with a scope that allows reading of file content. For example, an app using the drive.readonly.metadata scope would not be authorized to download the file contents. Users with edit permission may restrict downloading by read-only users by setting the viewersCanCopyContent field to true.

尝试使用Files.get获取音频文件的webContentLink。当此链接在新窗口中被点击或打开时,音频文件将被下载。

它看起来是这样的:

​​
+0

感谢。我知道了。 我发现了错误。在URL中不需要?alt = media。 – yongwoon

+0

我检查网站的回复。 – yongwoon