0

To work with google Drive, google developer portals says that

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];

This is my url for normal document/text file and

2

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

This is my url for pdf files.. however none of url works for me

I come to now for #1 that if I replace my url with kClientID as

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

Its working fine for normal text/document files…. But not sure how to access PDF file url.

Community
  • 1
  • 1
Kanjariya-IOS
  • 652
  • 1
  • 5
  • 17

1 Answers1

0

If you are using google drive sdk api you can download files something like,

 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);
}
}];

You will get files as data. You can store it in document directory. Or you can load it on webview to show. If file is pdf then you can load it on webview.

You can refer this stackoverflow link for more details. refer it's answer all step mentioned.

Hope this will help :)

Community
  • 1
  • 1
Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75