How to download public-shared file from Google Drive (without Drive API) using Objective C

410 Views Asked by At

I currently upload some files on my Google Drive, then create shared links for these files. These shared links has forms

https://drive.google.com/uc?export=download&confirm=wAFv&id=[may_be_file_id]

I create an app that can download these files. I use ASIHTTPRequest open source library to download those files

ASIHTTPRequest* req = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:<downloadURL>]];
req.shouldContinueWhenAppEntersBackground = YES;
req.timeOutSeconds = 60;
req.delegate = self;
req.tag = filename;

[req setDownloadDestinationPath:<a_video_path_on_Document_directory>];


ASINetworkQueue* networkQueue = [[ASINetworkQueue alloc] init];

[networkQueue addOperation:req];
[networkQueue setRequestDidFinishSelector:@selector(finishCallback:)];
[networkQueue setRequestDidFailSelector:@selector(failCallback:)];
[networkQueue setDelegate:self];

[networkQueue go];

The argument 'downloadURL' is shared url of each I mentioned above. But after the 'go' method of networkQueue invoke, the finishCallback is called immediately although the file size is about 2Gb. I tried with another downloader third party opensource but get the same result.

Is the problem on URL or Google Drive has done something to prevent download, but when I paste these URL on Safari on my Macbook, it downloads files OK.

What the problem here?

I just use Google Drive API to download its files.

GTLRDriveService* service = [[GTLRDriveService alloc] init];
        GTMSessionFetcher *fetcher = [service.fetcherService fetcherWithURLString:downloadURL]; //GTLServiceDrive *service;

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

And it runs into completion block immediately and print 'Retrieved file content'.

How can it be?

0

There are 0 best solutions below