2

I'm using the GoogleDrive Objective-C SDK, and I'm running into an issue. I want to build up a path -> ID mapping structure, so I ask Drive for a list of all of a users files. Normally this works fine. But, in cases where users have very large amounts of files, the server returns an internal error. I can fix this by setting the maxResults property on my GTLQueryDrive to a lower number. When I do that, everything works as expected, EXCEPT that the nextPageToken (and nextLink) property of the GTLDriveFileList is nil. I believe I need this nextPageToken to continue grabbing file information. I have tried setting the fields property on my query to nil, to a string that includes nextPageToken, and to a string that does not include nextPageToken. The nextPageToken property appears to be nil in all cases. Is there something I am missing? Thanks!

Ali Afshar
  • 40,967
  • 12
  • 95
  • 109
garrettm
  • 71
  • 6
  • Can you post sample code to reproduce it? Also, you may want to check if you're setting shouldFetchNextPages to YES or NO. If YES, it will automatically retrieve each page when you execute the code. No nextPageToken will be available in that case. – Steve Bazyl Nov 13 '12 at 22:51
  • Thanks for your reply! I had forgotten about shouldFetchNextPages. I do have it set to YES, but it appears to not fetch any extra information (ie. if I set maxResults to X, I only get X results in the callback, even though I have more than X files). – garrettm Nov 14 '12 at 21:54
  • Okay, I'm bad at stackoverflow. Here's my full reply: Thanks for your reply! I had forgotten about shouldFetchNextPages. I do have it set to YES, but it appears to not fetch any extra information (ie. if I set maxResults to X, I only get X results in the callback, even though I have more than X files). Am I missing something? I've tried to look through the documentation to see if there rest of the data might be attached to the ticket or the fileList in some other way, but I can't find anything. When I turn off shouldFetchNextPages, I am able to see nextPageToken just fine. – garrettm Nov 14 '12 at 22:03
  • With automatic loading of pages, you should see the aggregated results in the .items property. If you watch the log from you're app, you should see a log entry along the lines of "Executing drive.files.list required fetching 4 pages; use a query with a larger maxResults for faster results" – Steve Bazyl Nov 15 '12 at 18:59

1 Answers1

-1

Adding answer based on comment chain.

Here's a little sample that you can experiment with.

driveService.shouldFetchNextPages = YES;

GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.maxResults = 5;
// queryTicket can be used to track the status of the request.
[driveService executeQuery:query
    completionHandler:^(GTLServiceTicket *ticket, GTLDriveFileList *files,
                        NSError *error) {
        if (files) {
            NSLog(@"Have response %@", files.items);
            NSLog(@"Token %@", files.nextPageToken);
            NSLog(@"Count %d", files.items.count);
        }
    }];

With shouldFetchNextPages set to YES, the result will not contain a nextPageToken. Instead, assuming you have more than 5 files (based on maxResults) you'll still get the full list, along with a message in the log file that will look something along the lines of:

Executing drive.files.list required fetching 4 pages; use a query with a larger maxResults for faster results

If you set shouldFetchNextPages to NO, the result will be capped at 5 results in this case, and nextPageToken will have a valid token for getting the next page in the result set.

Steve Bazyl
  • 11,002
  • 3
  • 21
  • 24
  • Hi Steve, thanks for this. My code looks the same, except I explicitly set the fields property for the query: query.fields = @"kind,etag,items(id,labels,downloadUrl,exportLinks,originalFilename,title,kind,mimeType,userPermission,modifiedDate,parents,fileExtension)"; When I use shouldFetchNextPages NO, I include nextPageToken in fields, and all works well. But, if I set maxResults to 5, I only get 5 results in my file list. – garrettm Nov 15 '12 at 19:23
  • Okay, the problem was that nextPageToken is required for shouldFetchNextResults to work. This is a bit confusing, as when you finally get the block callback with shouldFetchNextResults set to YES, nextPageToken is nil, because there are no more pages (duh). But this made me think I didn't need it in fields. Everything is working fine now. Thanks for your help, and sorry to be a bother! – garrettm Nov 15 '12 at 19:50
  • According to the documentation, the query will fetch next pages up to a maximum of 25 pages when using shouldFetchNextResults. So it's not correct to say you will get a full list. You will get a full list only if the full list is smaller than 25 * results per page. – Victor Engel Oct 31 '15 at 15:24