OStack程序员社区-中国程序员成长平台

标题: ios - 如何在 IOS 中从 google drive V3 API 下载 pdf? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:37
标题: ios - 如何在 IOS 中从 google drive V3 API 下载 pdf?

使用 Google Drive V3 API 下载文件和 pdf。

  1. 根据 Google Doc,下面的 Google Drive V3 Api 是下载文件(比如文本文件)的 Url。

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

但是,当我简单地使用此 url 时,它在下载文件时给了我错误,然后我尝试使用客户端 ID 进行类似的操作,并且工作正常。(这里我删除了 alt=media 并在 url 中添加了客户端 ID。这是完美的工作正常)。下面是修改后的网址。

`NSString *url = [NSStringstringWithFormat"https://www.googleapis.com/drive/v3/files/%@?key=%@", file.identifier,kClientID];`
  1. 现在他们在 Google Doc 中提到使用以下网址的 pdf。

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

我再次面临同样的问题..上面下载 pdf 的 url 给了我错误。我已经完成了与 url 的所有排列和组合,但没有成功。

***文档中提供的示例代码使用的是google drive V2 Api。

那么,如何使用 Google Drive V3 Api 下载 pdf?请帮助。



Best Answer-推荐答案


今天,我从 Google Drive V3 Api 下载文件成功。

self.fileSize = [loadFile.quotaBytesUsed unsignedIntegerValue];

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        GTMSessionFetcher *fetcher = [GTMSessionFetcher fetcherWithURLString:loadFile.webContentLink];
        if(fetcher==nil)
        {
            break;
        }

        fetcher.authorizer             = [GTLServiceDrive sharedServiceDrive].authorizer;
        fetcher.destinationFileURL     = [NSURL fileURLWithPath:self.intoPath];

        __block typeof(self) blockSelf = self;
        fetcher.downloadProgressBlock  = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) {
            //get download progress
        };

        ////////////////////////////////////////////////////////////////////////////////////////////////////
        [fetcher beginFetchWithDelegate:self didFinishSelectorselector(fetcher:finishedWithData:error];

关于ios - 如何在 IOS 中从 google drive V3 API 下载 pdf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37339785/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4