如何在iOS下载谷歌驱动V3 API的pdf? [英] How to download pdf from google drive V3 API in IOS?
问题描述
使用 Google Drive V3 API
下载文件和pdf。
- 按照Google Doc的说法,下面的Google Drive V3 Api是下载文件(比如文本文件)的网址。
$ bNSString * url = [NSString stringWithFormat:@https://www.googleapis.com/drive/v3/files/%@?alt=media,file.identifier];
然而,当我简单地使用这个URL时,它给我在下载文件时出错,然后我用Client ID和它的工作正常尝试了这样的事情。在这里,我删除了alt = media,并在url中添加了客户端id。它完全正常工作).Below是修改过的url。
pre $
`NSString * url = [NSStringstringWithFormat:@https://www.googleapis.com/drive/v3/files/%@?key=%@,file.identifier,kClientID];`
-
现在,他们在Google Doc中提到要使用pdf以下网址。
NSString * url = [NSString stringWithForm at:https://www.googleapis.com/drive/v3/files/%@/export?alt=media&mimeType=application/pdf,file.identifier];
再次im面临同样的问题..上面的网址下载PDF给我的错误。我做了所有的
*** Doc中提供的示例代码使用的是谷歌驱动器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){
//获取下载进度
};
////////////////////////////////////////// ////////////////////////////////////////////////// ////////
[fetcher beginFetchWithDelegate:self didFinishSelector:@selector(fetcher:finishedWithData:error :)];
Working with the Google Drive V3 API
to download files and pdf.
As per Google Doc, Google Drive V3 Api below is the Url to download files(say text file).
NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?alt=media",file.identifier];
However when i simply used this url, it gives me error while downloading files then i tried something like this with Client ID and its working fine.(here i removed alt=media and added client id in the url.Which is perfectly working fine).Below is the modified url.
`NSString *url = [NSStringstringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?key=%@", file.identifier,kClientID];`
Now for pdf they have mentioned in the Google Doc to use the below url.
NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@/export?alt=media&mimeType=application/pdf", file.identifier];
Again i m facing the same problem..the above url for downloading the pdf giving me the error.i have done all the permutation and combination with the url with no success.
***The Sample code provided in the Doc is using google drive V2 Api.
So,How to download pdf with the use of Google Drive V3 Api?Please help.
解决方案 Today, I success for download file from 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:)];
这篇关于如何在iOS下载谷歌驱动V3 API的pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!