Swift Google Drive下载文件

时间:2014-08-19 15:55:46

标签: swift google-drive-api

我无法弄清楚如何在Swift中下载Google云端硬盘文件。我按照Google Objective-C API 'GTL' with Swift的修改后的快速入门进行了操作。我无法在下载文件时从Google Drive API翻译目标C代码。我四处搜寻,找不到任何东西。我怎样才能让它发挥作用?

2 个答案:

答案 0 :(得分:2)

您可以使用此功能在Swift中使用Google Drive API下载文件:

select *
from
(
  select -- plus other columns you want in the final result
     IncomeDay,
     Value = Cast(IncomeAmount as numeric(10,2))
  from DailyIncome
) d
pivot 
(
  SUM (Value) 
  for IncomeDay in ([MON],[TUE],[WED],[THU],[FRI],[SAT],[SUN])
) as AvgIncomePerDay

(在这种情况下,func downloadFile(file: GTLDriveFile){ let url = "https://www.googleapis.com/drive/v3/files/\(file.identifier!)?alt=media" let fetcher = drive.fetcherService.fetcherWithURLString(url) fetcher.beginFetchWithDelegate( self, didFinishSelector: #selector(ViewController.finishedFileDownload(_:finishedWithData:error:))) } drive - 与Documentation中的相同

然后你需要实现下载完成后调用的函数GTLServiceDrive

finishedFileDownload

答案 1 :(得分:0)

实际适用于Swift 5。

func download(file: GTLRDrive_File) {
    let url = "https://www.googleapis.com/drive/v3/files/\(file.identifier!)?alt=media"
    let fetcher = drive.fetcherService.fetcher(withURLString: url)
    fetcher.beginFetch(completionHandler: { data, error in
        if let error = error {
            print(error.localizedDescription)
        }

        //Do something with data
    })
}