2016-12-06 66 views
2

我想用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 
    } 

} 

回答

1

關於這裏你 「讀訪問」 的問題是什麼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