0

我正在使用 Google API Client for REST Library 为我的 mac 应用程序实现 Google Drive Api,

- (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);


                      }];
}

这里是返回值

GTLRDrive_FileList 0x6080002404e0:{种类:“drive#fileList”文件:[5]}

我的驱动器上有 7 个项目,但它只返回 5 个项目?

4

1 回答 1

0

它可能与您的nextPageToken有关。它只返回某个页面的结果,而不是全部。

检查此文档

有时查询可能会返回大量结果,这些结果一次返回一页。当结果对象包含 nextPageToken 字符串时,可以再次执行查询;提供返回的令牌作为新查询的 pageToken 属性,获取下一组结果。您可以重复此操作,直到到达最后一页,该页面不会包含 nextPageToken 字符串。

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);
  }
}];

尝试iOS 快速入门中的 Drive 示例,了解如何正确获取文件。这是一个片段:

/ 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:)];
}
于 2016-07-05T06:52:58.217 回答