【问题标题】:How to download PDF file url from google drive with latest IOS SDK?如何使用最新的 IOS SDK 从谷歌驱动器下载 PDF 文件 url?
【发布时间】:2016-05-20 14:52:47
【问题描述】:

要使用 google Drive,Google 开发者门户网站表示

https://developers.google.com/drive/ios/devguide/files#reading_files

1

NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?alt=media",file.identifier];

这是我的普通文档/文本文件的网址和

2

NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@/export?alt=media&mimeType=application/pdf", file.identifier];

这是我的 pdf 文件网址.. 但是没有一个网址适合我

我现在来到#1,如果我将我的 url 替换为 kClientID 为

NSString *url = [NSStringstringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?key=%@", file.identifier,kClientID];

它适用于普通文本/文档文件……。但不确定如何访问 PDF 文件 url。

【问题讨论】:

  • 无法理解您的问题...!!你到底想要什么??????
  • @Lion,我无法从谷歌驱动器下载 pdf 文件
  • 您尝试下载文件的代码在哪里?您只需添加三个包含 url 的字符串!
  • 根据谷歌文档的第二个,但它对我不起作用:(不知道我犯了什么错误

标签: ios objective-c pdf


【解决方案1】:

如果您使用的是 google drive sdk api,您可以下载类似的文件,

 GTMHTTPFetcher *fetcher =
[self.driveService.fetcherService fetcherWithURLString:downloadUrl];    
//async call to download the file data
 [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
if (error == nil) {
    NSLog(@"\nfile %@ downloaded successfully from google drive", self.selectedFileName);

    //saving the downloaded data into temporary location
    [data writeToFile:<path> atomically:YES];               
} else {
    NSLog(@"An error occurred: %@", error);
}
}];

您将获得文件作为数据。您可以将其存储在document directory。或者您可以将其加载到webview 以显示。如果文件是pdf,那么您可以将其加载到webview

您可以参考this stackoverflow link 了解更多详情。参考它提到的所有步骤的答案。

希望这会有所帮助:)

【讨论】:

  • 我需要使用 GTMSessionFetcher,而不是 API 版本 2,即使用 GTMHTTPFetcher ;(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-12
  • 1970-01-01
  • 2016-09-24
  • 1970-01-01
相关资源
最近更新 更多