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!
2
votes
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
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
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
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
1 Answers
-1
votes
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.