如何在IOS中从谷歌驱动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 =媒体并在url中添加了客户端ID。这是完全正常工作) .Below是修改后的url。

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

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

我再次面临同样的问题..以上url下载pdf给我error.i做了所有的排列和组合与url没有成功。

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

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

今天,我成功从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 didFinishSelector:@selector(fetcher:finishedWithData:error:)]; 

– (void)downloadFile:(NSString *)url {

 GTMSessionFetcher *fetcher = [GTMSessionFetcher fetcherWithURLString:url]; fetcher.authorizer = [[GTLServiceDrive alloc]init].authorizer; fetcher.destinationFileURL = [NSURL fileURLWithPath:url]; __block typeof(self) blockSelf = self; fetcher.downloadProgressBlock = ^(int64_t bytesWritten, int64_t totalBytesWritten, int64_t totalBytesExpectedToWrite) { //get download progress NSLog(@"bytesWritten = %d",bytesWritten); NSLog(@"totalBytesWritten = %d",totalBytesWritten); NSLog(@"totalBytesExpectedToWrite = %d",totalBytesExpectedToWrite); }; [fetcher beginFetchWithDelegate:self didFinishSelector:@selector(fetcher:finishedWithData:error:)]; 

}

@Andrew Lai,@ samar我对“如何在Drive V3中下载”的问题感到困惑。现在,我可以获得file.webContentLink,但我找不到下载文件的方法。 帮帮我〜