Google Drive iOS SDK:获取用户空间

Wil*_*ill 3 objective-c ios google-drive-api

我正在构建一个使用Google Drive iOS SDK将文件上传到用户的Google云端硬盘帐户的应用.由于正在上传的文件的大小,我想知道用户使用了多少空间并且可用.例如,我计划在我的应用程序中有一个标签,显示用户当前正在使用10gb/100gb.

我猜可能有办法从初始登录中获取此信息,但我希望能够即时获取此信息.

提前致谢!

Tyl*_*hes 7

您可以查询"关于"资源以获取此信息.相关文档还包含一些示例代码:https://developers.google.com/drive/v2/reference/about/get

#import "GTLDrive.h"
// ...

+ (void)printAboutWithService:(GTLServiceDrive *)service {
  GTLQueryDrive *query = [GTLQueryDrive queryForAboutGet];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveAbout *about,
                            NSError *error) {
          if (error == nil) {
            NSLog(@"Current user name: %@", about.name);
            NSLog(@"Root folder ID: %@", about.rootFolderId);
            NSLog(@"Total quota (bytes): %@", about.quotaBytesTotal);
            NSLog(@"Used quota (bytes): %@", about.quotaBytesUsed);
          } else {
            NSLog(@"An error occurred: %@", error);
          }
        }];
}

// ...
Run Code Online (Sandbox Code Playgroud)