• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

ios - 如何在 IOS 中从 google drive V3 API 下载 pdf?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 16:37:52 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

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

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap