0

I'm implementing Google Drive Api for my mac application using Google API Client for REST Library below,

- (void)fetchFileList {

_fileList = nil;
_fileListFetchError = nil;


GTLRDriveService *service = self.service;

GTLRDriveQuery_FilesList *query = [GTLRDriveQuery_FilesList query];

// Because GTLRDrive_FileList is derived from GTLCollectionObject and the service
// property shouldFetchNextPages is enabled, this may do multiple fetches to
// retrieve all items in the file list.


query.fields = @"kind,nextPageToken,files(mimeType,id,kind,name,webViewLink,thumbnailLink,trashed)";



_fileListTicket = [service executeQuery:query
                      completionHandler:^(GTLRServiceTicket *callbackTicket,
                                          GTLRDrive_FileList *fileList,
                                          NSError *callbackError) {
                          // Callback
                          _fileList = fileList;
                          _fileListFetchError = callbackError;
                          _fileListTicket = nil;



                          NSLog(@"%@", fileList);


                      }];
}

Here the return value

GTLRDrive_FileList 0x6080002404e0: {kind:"drive#fileList" files:[5]}

There are 7 items on my drive but it returns only 5 items?

Pang
  • 9,564
  • 146
  • 81
  • 122
webmastx
  • 683
  • 1
  • 8
  • 30

1 Answers1

0

It may have something to do with your nextPageToken. It returned only the result of a certain page, not all of them.

Check this docs:

Sometimes a query may return a large number of results, which are returned one page at a time. When a result object includes a nextPageToken string, you can execute the query again; supply the returned token as the pageToken property of the new query, fetching the next set of results. You can repeat this until you reach the last page, which will not inlude a nextPageToken string.

GTLServiceDrive *drive = ...;
GTLQueryDrive *query = [GTLQueryDrive queryForFilesList];
query.q = search;
[drive executeQuery:query completionHandler:^(GTLServiceTicket *ticket,
                                              GTLDriveFileList *fileList,
                                              NSError *error) {
  if (error == nil) {
    NSLog(@"Have results");
    // Iterate over fileList.files array
  } else {
    NSLog(@"An error occurred: %@", error);
  }
}];

Try the Drive sample from the iOS Quickstart on how to fetch Files properly. Here's a snippet:

/ Construct a query to get names and IDs of 10 files using the Google Drive API.
- (void)fetchFiles {
  self.output.text = @"Getting files...";
  GTLQueryDrive *query =
  [GTLQueryDrive queryForFilesList];
  query.pageSize = 10;
  query.fields = @"nextPageToken, files(id, name)";
  [self.service executeQuery:query
                    delegate:self
           didFinishSelector:@selector(displayResultWithTicket:finishedWithObject:error:)];
}
ReyAnthonyRenacia
  • 17,219
  • 5
  • 37
  • 56
  • It returns 7 items correctly ONLY the first run of the application (Click Run) since boot! Now, the second run and afterward returns 0 !!!!! This give me an headache!! – webmastx Jul 07 '16 at 05:39
  • noogui, I'm using the same code and notice the problem occurs ONLY after the first run! (Run -> Stop -> Run again) – webmastx Jul 07 '16 at 05:47