我想使用 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 .单击或在新窗口中打开此链接时,将下载音频文件。
看起来像这样:
https://drive.google.com/uc?id=0Bzgk4zccNwI7TzBxZTFzbHFhdUU&export=download
关于ios - 如何下载音频文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986035/