ios - 如何下载音频文件?

标签 ios google-drive-api swift3

我想使用 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/

相关文章:

ios - iOS10 高度问题中的 Today widget swift

ios - 如何从数据库在 map 上绘制图 block ?

swift - 在 [UInt8] 数组或数据中包含 UTF8 字 rune 字

swift - 如何在类层次结构中正确实现 Equatable 协议(protocol)?

ios - 如何在 iOS 中使用 google maps sdk 显示 "national parks"等地点?

iOS WatchKit - 如何向 Storyboard 中的 WKInterfaceTable 添加一行多行

ios - 将快速添加方法包含到 UITableView 的方法

python - 如果文件夹已存在于谷歌驱动器中,如何跳过文件夹创建? (Py驱动器)

javascript - 使用 google Drive API 与特定用户共享上传的文件

python - 如何使用 python Telegram Bot API 将文件上传到谷歌驱动器