How to download a file from Google Drive using object c?

I work with download files from Google Drive. But I ran into a lot of problems using the Google SDK. There are several examples on developers.google.com.

 GTLServiceDrive *drive = ...;

    GTLDriveFile *file = ...;

    GTMHTTPFetcher *fetcher = [drive.fetcherService fetcherWithURLString:file.downloadUrl];`

    `[fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
      if (error == nil) {
        NSLog(@"Retrieved file content");
        // Do something with data
      } else {
        NSLog(@"An error occurred: %@", error);    
      }
    }];

I downloaded the new sdks from the site developer.google.com, but the above example is given GTMHTTPFetcher *fetcher = [drive.fetcherService fetcherWithURLString:file.downloadUrl];. But GTLDriveFilethere is no object in the new SDK downloadURL.

And in another example, it asks for the client’s secret key, but when I select the iOS type, then there is no key for the client’s secret key. But when I select the web, this time is shown. but it does not work.

Please help me download a file from Google Drive in iOS using target c.

+4
source share
2

( API iOS) URL

GTLDriveFile *myfile;//Your File Object
    NSString *url = [NSString stringWithFormat:@"https://www.googleapis.com/drive/v3/files/%@?key=YOUR_KEY_iOS",
                     myfile.identifier];
    GTMSessionFetcher *fetcher = [self.service.fetcherService fetcherWithURLString:url]; //GTLServiceDrive *service;

    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
        if (error == nil) {
            NSLog(@"Retrieved file content");
            // File Downloaded!
        } else {
            NSLog(@"An error occurred: %@", error);
        }
    }];
+1

google:

https://developers.google.com/drive/v2/reference/files/get

+ (void)downloadFileContentWithService:(GTLServiceDrive *)service
                                  file:(GTLDriveFile *)file
                       completionBlock:(void (^)(NSData *, NSError *))completionBlock {
  if (file.downloadUrl != nil) {
    // More information about GTMHTTPFetcher can be found on
    // <a href="http://code.google.com/p/gtm-http-fetcher">http://code.google.com/p/gtm-http-fetcher</a>
    GTMHTTPFetcher *fetcher =
      [service.fetcherService fetcherWithURLString:file.downloadUrl];

    [fetcher beginFetchWithCompletionHandler:^(NSData *data, NSError *error) {
      if (error == nil) {
        // Success.
        completionBlock(data, nil);
      } else {
        NSLog(@"An error occurred: %@", error);
        completionBlock(nil, error);
      }
    }];
  } else {
    completionBlock(nil,
                    [NSError errorWithDomain:NSURLErrorDomain
                                        code:NSURLErrorBadUrl
                                    userInfo:nil]);
  }
}

, :

'GTL;DRiveFile' 'downloadUrl'

0

Source: https://habr.com/ru/post/1629844/


All Articles